2 ms·
The earliest C++ compilers compiled to C, and I believe that's still possible to do even for the latest versions of the C++ standard.
by userbinator 2y ago
The earliest C++ compilers compiled to C, and I believe that's still possible to do even for the latest versions of the C++ standard.
- nextaccountic 2y agoIt's always possible to compile a turing complete language into another turing complete language, so this statement doesn't carry much meaning. The interesting thing with the original C++ (then called "C with classes") compiler, Cfront, which compiled to C, was that it was an 1:1 transpiler that offered only local transformations with no global analysis (you can transform one function at time without looking at the rest of the code). The structure of the generated C code closely matched the C++ source code. This is something that's not always possible when compiling a language into another, this only happens when a language offers essentially just syntactic sugar over another, like Coffeescript and Javascript. I guess that if you compile exceptions using setjmp/longjmp and expanded all templates (I don't think you can compile templates into C macros), and also expanded method overloading and type inference, then all other features from modern C++ are only local transformations. Well maybe with the exception of couroutines from C++20 (which maybe can be compiled into setjmp/longjmp as well, if it can interact well with exceptions? But the purpose of couroutines is to compile into a state machine, which is a non local transformation) The original Cfront compiler didn't implement even exceptions (they wanted to but Wikipedia said the code was a mess [0] so it was abandoned), but that another, later C++ compiler [1] compiled into C and implemented exceptions and other things [0] https://en.wikipedia.org/wiki/Cfront https://en.wikipedia.org/wiki/Cfront [1] https://en.wikipedia.org/wiki/Comeau_C/C%2B%2B https://en.wikipedia.org/wiki/Comeau_C/C%2B%2B