3 ms·
> ...many C programs will compile just fine with a C++ compiler Unfortunately(?) that's only true for C code written in the early 90s or specifically for the c
by flohofwoe 2y ago
> ...many C programs will compile just fine with a C++ compiler
Unfortunately(?) that's only true for C code written in the early 90s or specifically for the common C/C++ subset (which is essentially a subset of both C and C++ based on a non-standard snapshot of C ca 1995).
Since C99, the two languages have diverged enough that C is no longer a subset of C++, and IMHO propagating the idea that there's a 'C subset' in C++ 25 years after the 'schism' is harmful both for C and C++.
- Calavar 2y agoInterestingly though, compatibility in the reverse direction has actually gotten better over time. C99 allows variables to be declared at any point in a function. Before C99, the all variables up front rule used to be the single biggest reason that C-style C++ code wouldn't compile under a C compiler.
- flohofwoe 2y agoMany C compilers accepted this as non-standard extension already before C99 though (along with winged comments, and `for (int...)`). There is a lot of useful harmonization happening between the two languages (and mostly from the direction of C++ to C) From the perspective of a C coder, the one good thing about C++ is that it is basically the testing ground for new potential C features to figure out what works and doesn't work in realworld scenarios before the C standard is polluted too much with the ideas that don't work ;)
- knorker 2y agoI feel like the article is already implying this: > Despite this, C++ preserves a huge amount of C heritage and many C programs will compile just fine with a C++ compiler It preserves "a huge amount", not "backwards compatability". "Many" C programs will compile, not "all". Hell, the author didn't even go as far as to say "most". Also the author says: > The original version of C++ WAS basically an object oriented version of C ("C with classes") BUT AT THIS POINT it has been around for 40-odd years and so HAS DIVERGED VERY SIGNIFICANTLY [my emphasis / capitalization] I'm not sure what point you're making that's not already in the article.
- pjmlp 2y agoPartially, ISO C++ has been updating the underlying C standard library reference, to the extent it is compatible with C++, C++23 refers to C17 and the upcoming C++26 will refer to C23, standard library that is. However this is exactly the golden example why guest languages never own the platform (in this case UNIX/POSIX/C trio), and eventually the platform and guest always diverge. Even though both share the same birthplace, as usual adoption takes different routes. If one never wants to face this, regardless how many pain points the language owning the platform has, sticking to it always wins out in the long run.
- bluGill 2y agoThere are people on the C standard commitee with their main goal keep C tompatible with C++. They don't win ever debate but they win many.
- pjmlp 2y agoI don't doubt it, unfortunately design by committee has its constraints. For example, had C kept under control by its authors, maybe even the security story would have been sorted out by now, who knows.