News for hackers. Stuff that matters.
Re:C as an intermediate language (2012) by WalterBright on Saturday January 20, 2018 @02:43PM (#16195031)
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.

Re:C as an intermediate language (2012) by WalterBright on Saturday January 20, 2018 @03:53PM (#16195369)
Another 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.

Re:C as an intermediate language (2012) by zzzcpan on Saturday January 20, 2018 @04:06PM (#16195432)
Well, 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.
Re:C as an intermediate language (2012) by stingraycharles on Saturday January 20, 2018 @02:53PM (#16195077)
> 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 ?

Re:C as an intermediate language (2012) by WalterBright on Saturday January 20, 2018 @03:51PM (#16195359)
Things 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.

Re:C as an intermediate language (2012) by rdc12 on Saturday January 20, 2018 @06:27PM (#16196000)
If you were writing D from scratch today, would you go for a full back end solution or would you target the LLVM?
Re:C as an intermediate language (2012) by WalterBright on Saturday January 20, 2018 @08:16PM (#16196361)
There's already LDC, a D compiler using the LLVM. The 3 D compilers (DMD, GDC, LDC) nicely complement each other.