Hacker News new | ask | show | jobs
by userbinator 3659 days ago
while simultaneously destroying the possibility of it ever being self-hosting.

...at least until it begins turning into a C++ compiler ;-)

That makes me wonder, given that there seem to be quite a lot of "toy" C/C-subset compilers being written these days, just how much harder C++ would be. For a long time it was commonly thought that even the simplest C compiler would be extremely complex and difficult, but that notion appears to have been somewhat defeated, so the next logical step in that direction is C++ or maybe C++-to-C (like Cfront) compilers. The closest I'm aware of would be the C++-subset used in TempleOS, which is self-hosting.

1 comments

Horribly. C++ has so many features, and interactions between them, that you really don't want to be dragged into that as a toy project. I'd wager that the C++ language spec is longer than the source of a functional C compiler (both without the standard libraries).
Maybe the interactions aren't actually the issue because the features are quite orthogonal and independent of each other, and the complexity is really the natural result of the interactions between them. If I wanted to write a C++ compiler I'd probably start by adding features in this order:

    - Member functions in structures; constructors; destructors
    - Single inheritance
    - Virtual functions
    - Exceptions
    - Multiple inheritance
    - Virtual inheritance
    - Templates
There's definitely more I haven't listed, but the first few don't seem too difficult...