6 ms·
The chief benefits to pure C IMO are that it's more portable, compiles faster, and it's a simple and stable language. Writing C takes more effort in some cases
by mtdewcmu 10y ago
The chief benefits to pure C IMO are that it's more portable, compiles faster, and it's a simple and stable language.
Writing C takes more effort in some cases, so it's a trade-off.
- maxlybbert 10y agoIt'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.)
- mtdewcmu 10y agoA 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.