This question was triggered by replie(s) to a post by Herb Sutter where he explained MS's decision to not support/make a C99 compiler but just go with the C(99) features that are in the C++(11) standard anyway.
One commenter replied:
(...) C is important and deserves at least a little bit of attention.
There is a LOT of existing code out there that is valid C but is not valid C++. That code is not likely to be rewritten (...)
Since I only program in MS C++, I really don't know "pure" C that well, i.e. I have no ready picture of what details of the C++-language I'm using are not in C(99) and I have little clues where some C99 code would not work as-is in a C++ compiler.
Note that I know about the C99 only
restrict keyword which to me seems to have very narrow application and about variable-length-arrays (of which I'm not sure how widespread or important they are).
Also, I'm very interested whether there are any important semantic differences or gotchas, that is, C(99) code that will compiler under C++(11) but do something differently with the C++ compiler than with the C compiler.
Quick links: External resources from the answers:
- Wikipedia page
- David R. Tribble's comparison (from 2001)
- C++11 standard: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3376.pdf (section C.1)
If you start from the common subset of C and C++, sometimes called clean C (which is not quite C90), you have to consider 3 types of incompatibilities:
Additional C++ featues which make legal C illegal C++
Examples for this are C++ keywords which can be used as identifiers in C or conversions which are implicit in C but require an explicit cast in C++.
This is probably the main reason why Microsoft still ships a C frontend at all: otherwise, legacy code that doesn't compile as C++ would have to be rewritten.
Additional C features which aren't part of C++
The C language did not stop evolving after C++ was forked. Some examples are variable-length arrays, designated initializers and
restrict. These features can be quite handy, but aren't part of any C++ standard, and some of them will probably never make it in.
Features which are available in both C and C++, but have different semantics
An example for this would be the linkage of
A list of incompatibilities between C99 and C++98 can be found here (which has already been mentioned by Mat).
While C++11 and C11 got closer on some fronts (variadic macros are now available in C++, variable-length arrays are now an optional C language feature), the list of incompatibilities has grown as well (eg generic selections in C and the
auto type-specifier in C++).
As an aside, while Microsoft has taken some heat for the decision to abandon C (which is not a recent one), as far as I know no one in the open source community has actually taken steps to do something about it: It would be quite possible to provide many features of modern C via a C-to-C++ compiler, especially if you consider that some of them are trivial to implement. This is actually possible right now using Comeau C/C++, which does support C99.
However, it's not really a pressing issue: Personally, I'm quite comfortable with using GCC and Clang on Windows, and there are proprietary alternatives to MSVC as well, eg Pelles C or Intel's compiler.