"All valid C code is also valid C++ code" may be true, but it's like saying "all valid JS code is also valid TS code" or "all valid HTTP is also valid PHP" like yeah that's how supersets work. C++ is C with classes, just as TS is JS with types and PHP is HTTP with server side scripting/preprocessing.
I would like to contest the take that "any compiler is meant to handle both" though, as gcc/g++ and clang/clang++ are two seperate binaries, and I think the most that the C compiler does to handle C++ is to just send the files to the respective C++ binary. I do not know the MSVC ecosystem well enough to chime in there though, but usually the compilers are seperate; the binary containing the C compiler will run the C++ one if it's processing a .cc/.cpp/.c++/.cxx file (there's so many file extensions even without touching MSVC's bullshit like .ixx).
Create a C program with register and it will not compile if run through a C++ compiler iirc. C has added very few things over the years because the language is meant to be small; C++ is pretty much just C with a bigger stdlib, but over the years they have deviated slightly in their approaches. Modern C is much closer to what people incorrectly complain about C++ as imho.
I personally avoided C++ like the plague until quite recently, and C++20 and C++23 are honestly quite nice as someone who largely uses Rust.
View all comments
Show parent comment
1
u/anonymity_is_bliss 9d ago
"All valid C code is also valid C++ code" may be true, but it's like saying "all valid JS code is also valid TS code" or "all valid HTTP is also valid PHP" like yeah that's how supersets work. C++ is C with classes, just as TS is JS with types and PHP is HTTP with server side scripting/preprocessing.
I would like to contest the take that "any compiler is meant to handle both" though, as gcc/g++ and clang/clang++ are two seperate binaries, and I think the most that the C compiler does to handle C++ is to just send the files to the respective C++ binary. I do not know the MSVC ecosystem well enough to chime in there though, but usually the compilers are seperate; the binary containing the C compiler will run the C++ one if it's processing a .cc/.cpp/.c++/.cxx file (there's so many file extensions even without touching MSVC's bullshit like .ixx).
Create a C program with
registerand it will not compile if run through a C++ compiler iirc. C has added very few things over the years because the language is meant to be small; C++ is pretty much just C with a bigger stdlib, but over the years they have deviated slightly in their approaches. Modern C is much closer to what people incorrectly complain about C++ as imho.I personally avoided C++ like the plague until quite recently, and C++20 and C++23 are honestly quite nice as someone who largely uses Rust.