I have read several times that early C++ compilers translated first C++ code into plain C before compiling it (or maybe needed a third-party C compiler).
Playing myself with grammar / language / compilation fields, I am curious to see how C++ was implemented in plain C, especially what can be one way to implement the class inheritance and [virtual] method calling.
Could you point me to such a compiler that would still be available nowadays?
I know that OO code can be simulated / emulated in plain C with structs and functions pointers, but I would like to see an actual implementation of the C++ language in C.
You can try cfront. You can download old versions here. But it only supports a very limited C++ subset. Some features like exceptions can not be implemented this way.
Update: As Maxim Yegorushkin noted Exceptions might be implemented with setjmp/longjmp. But if I remember correctly exceptions can not be implemented as an library in C++. They have to be part of the core language.
If you just want to see how C++ can be translated in C then you have several options available to you and the C++ FAQ has a section that covers this here. It cover all the major options I have ever seen suggested and should be updated when new options are available.
Comeau compiler works this way. In its heyday everyone was praising its standard compliance and used Comeau online to test snippets of code, but few were using it for building production codes.
EDGE frontend also works this way. I hear it is used by both Intel C++ compiler and Comeau.
The first Microsoft C++ compiler was exactly as you describe, I know because I remember using it. From my memory, I think it was version 7 of their C compiler. This would have been around 1992 (plus/minus 2 years).
Update: see http://en.wikipedia.org/wiki/Visual_C%2B%2B, the one that I'm referring to was indeed released in 1992 and called "C/C++ 7.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With