3 ms·
The common subset of C99 that compiles in both C and C++ is basically "C90 with // comments".
by kazinator 7y ago
The common subset of C99 that compiles in both C and C++ is basically "C90 with // comments".
- wahern 7y agoThere are many more, though what comes immediately to mind are variadic macros and long long. (Actually, here's a good list: https://stackoverflow.com/questions/47524553/are-all-of-the-features-of-c99-also-in-c https://stackoverflow.com/questions/47524553/are-all-of-the-...) Are there any widely used C++ compilers that don't also have a C personality? I've only ever worried about C++ compatibility in my headers. IME C and C++ toolchains make it relatively trivial to build and link C and C++ units together. However, I don't have much experience in the commercial embedded space (as opposed to x86 appliance "embedded"), which I've assumed were mostly C shops.
- flohofwoe 7y agoFor single-file libraries (declaration and implementation in one header) it's sometimes more convenient to include the header implementation into a C++ file (and not compile the implementation in a separate C file). Also, compiling C code in C++ mode might trigger a couple more warnings which are actually bugs. But these are the only reason I can think of compiling C code as C++.
- kazinator 7y ago> Are there any widely used C++ compilers that don't also have a C personality? All of them. If you mean "aren't accompanied by a C compiler front-end also", that's something else. If you want that C++ compiler's opinion about your code, then you have to pass it to the C++ compiler, not to its C cousin that has tagged along.
- flohofwoe 7y agoTry working a while with the strict ISO-C90 / C89 standard enforced in the compiler, it's tons of small (and some not so small) differences. With the usual clang/gcc extensions most of the pain points had been fixed long before C99 came along though.
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]