by _0ffh · 1y ago · 0 comments
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
And I believe the STL is also implemented that way as well.
i had the same reacion, then i realized
(and yes, i know the following opinion is a minority oldschool boomer opinion, no need to downvote me to hell to make sure i know)
JSON itself is the abuse of C/unix, like XML before it.