Re:C99/C11 dynamic array that mimics C++'s std::vector
by maxlybbert on Saturday January 07, 2017 @09:17PM
(#13347866)
It's goofy, but one of the reasons I'll pick C for a quick program is that both Windows and Linux will give better error messages for standard functions that fail and set errno than for equivalent C++ code that throws an exception.
This isn't a question about the language, it's definitely a quality-of-implementation issue for standard exceptions to have what() give a useful message.
Just to clarify perror will generally give a better error message in:
FILE* fh = fopen("foo.txt", "w+");
if (!fh) {
perror("unable to open foo.txt");
return 1;
}
Than what() will in: std::fstream fs;
fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
fs.open("too.txt");
}
catch (const std::exception& ex)
{
std::cerr << "unable to open foo.txt: "
<< ex.what() << '\n';
}
(Ignoring other issues such as whether exceptions are better than return codes, etc.)
Re:C99/C11 dynamic array that mimics C++'s std::vector
by mtdewcmu on Saturday January 07, 2017 @11:11PM
(#13348189)
A lot of people seem to use stdio even in C++.
Having comprehensible error messages is related to being a simple language, IMO. C++ compile-time errors are notorious for being unreadable. I'm not familiar with the output of what(), but I'd wager that the problem is a consequence of all the abstraction.
Writing C takes more effort in some cases, so it's a trade-off.