4 ms·
> (I know, it’s not technically a subset) Is it not? I thought C++ was explicitly a strict superset of C?
by taneq 6y ago
> (I know, it’s not technically a subset)
Is it not? I thought C++ was explicitly a strict superset of C?
- einpoklum 6y agoSyntactically, it almost was; and even this is no longer true today with C11 and later, More importantly, though - the syntax is not what matters. The languages are very very different in idiomatic use. You just don't write programs the same way with C and with C++. And the gulf between the two only expands with time. A decent C program is almost certainly a poor C++ program, in terms of idioms, utilization of library facilities, and sometimes even in terms of performance (!).
- janoc 6y agoIt is not and never was. Look at for ex. what const means in each, or auto. Or variable length arrays (feature that doesn't exit in C++). Or designated initializers that C++ didn't have for a long time. Here is a good list of differences: https://mcla.ug/blog/cpp-is-not-a-superset-of-c.html https://mcla.ug/blog/cpp-is-not-a-superset-of-c.html
- gmueckl 6y agoC++ is almost a perfect superset of old C before C99. There are odd corner cases where prograns are parsed differently, but these are quite contrived. The 3rd edition of The C++ Programming language lists a few cases. Since then, C has had may additions to the language that made it diverge from C++. Your linked article is almost entirely about these new C additions.
- janoc 6y agoEven for the old C it wasn't a superset. There are plenty of legal C programs that aren't legal C++ - if for nothing else, then because C++ has more reserved keywords which are perfectly legal identifier names in C. E.g. this is legal C but not legal C++: int template = 10;