3 ms·
C++, a more complex language in all dimensions managed to produce C code via the first C++ compiler, Cfront. Dlang has its own native code generator? You have
by sitkack 5y ago
C++, a more complex language in all dimensions managed to produce C code via the first C++ compiler, Cfront.
Dlang has its own native code generator? You have amazing chops, I am sure you could have emitted C code.
What are your thoughts on producing Wasm instead of C? Maybe Scheme is the perfect compiler target.
https://en.wikipedia.org/wiki/Cfront https://en.wikipedia.org/wiki/Cfront
- mhh__ 5y agoThe dmd code generator was/is a C++ compiler backend too, and can trace it's lineage back to the first compilers to make Cfront obsolete. We could emit C code, but it's just worse when you need to get to the cutting edge. Even if you end up going through the same backend via C, you've now (say) lost devirtualization.
- WalterBright 5y agocfront in the 80s was a far simpler C++ compiler than today. And if you ever looked at the code it generated, you'd be horrified. One major problem it had in generating C was the lack of COMDAT sections in the generated object file. This was needed for generating code for the same member function in multiple source files. C compilers would just stick the code into the text segment, resulting in multiple declaration errors from the linker. I am not saying Bjarne was an inept programmer. He's actually brilliant, it was just a very very hard problem he set for himself, and it's amazing cfront worked as well as it did. The cfront on DOS also was very slow (imagine writing the generated source code out to floppies!) and crippled because it didn't have near and far pointers. Zortech C++ was the first native C++ compiler, which bypassed all these problems. ZTC++ simply vaulted over cfront by making C++ simple and fast on DOS. DOS at the time was where 90% of the programming action was, so this was no small thing. My opinion, and that of a few others at the time, was that Zortech saved C++ from oblivion by having a usable implementation on DOS. You can see that by the traffic level in comp.lang.c++ at the time - it took off immediately after ZTC++ was released, and never looked back.
- sitkack 5y agoI always love your responses. I didn't know about COMDAT, but I did use the SAS compiler on the Amiga which was Cfront based. I didn't know enough to be horrified, but I often looked at the output because I was integrating the output with regular C code (interpreters, Arexx, etc). It was kinda like Hungarian Notation++ ;) I got to the point where it felt natural to read the name mangling. The Amiga SAS/C compiler was also pretty slow. I can see how ZTC would be popular in by skipping intermediates and not having to reinvoke the compiler. How many problems from the 80s melted away because of the large amount of ram available in the 90s?
- WalterBright 5y agoOne problem that melted away was the compiler's 3 separate passes could be merged into one! Also, the amount of code in the compiler increased enormously from the 80's to today.