4 ms·
I considered compiling D to C. The trouble is when you need to do things like exception handling, adjustor thunks, define things that are implementation defined
by WalterBright 9y ago
I considered compiling D to C. The trouble is when you need to do things like exception handling, adjustor thunks, define things that are implementation defined or undefined in C, etc. I figured I'd spend too much time struggling with that, and besides, it would make compilation slow.
> Without doubt, today the answer is C++ and Objective-C – languages whose first compilers emitted C code.
I wrote the first native C++ compiler for the PC. It was a huge win over the cfront based PC compilers, which were nearly unworkable.
- stingraycharles 9y ago> I figured I'd spend too much time struggling with that, and besides, it would make compilation slow. Is that only because of the extra compilation step, or are there other things making this more slow ?
- WalterBright 9y agoThings that make it slow: 1. Compile the code 2. Generate strings for C code (C is much larger than intermediate code). Translating things like integers to strings is slow. 3. Writing the file out, as opposed to just keeping the data in memory. C compilers are already slow (due to the preprocessor and phases of translation), so add your compiler on top of that, and you're going to have an unfixably slow solution.
- WalterBright 9y agoAnother problem I failed to mention is you don't have control over the C compiler the customer is using. It may behave differently, have bugs in it, etc., and the customer will blame you. Being unable to fix the C compiler means you'll be fixing the problem in the wrong place, making things pretty hard on you. I run into these sorts of problems with D's C++ interface. In particular, how "long long" and "long" are mangled when they are the same size, and when "long long" is used vs when "long" is used. It's an endless whack-a-mole problem.
- zzzcpan 9y agoWell, you don't have to generate raw C code and deal with all the compilers. It might be possible if your language doesn't have machine types, but if it does you have to do what C software usually does: test the compiler for various things and generate a header to rely on. Maybe even supply a ./configure script.
- rdc12 9y agoIf you were writing D from scratch today, would you go for a full back end solution or would you target the LLVM?
- WalterBright 9y agoThere's already LDC, a D compiler using the LLVM. The 3 D compilers (DMD, GDC, LDC) nicely complement each other.