Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Well I find it more interesting...

Also C compilers can do a lot of micro optimizations that are not trivial, so compiling something to C or maybe LLIR seems like a better choice.



sort by: page size:

I won't echo this sentiment, but; why use C for writing a compiler? It seems that languages in the ML family, among others, are nicer for that kind of domain.

I guess it at least has its uses if you want your compiler to be really fast.


Sorry for the stupid question, but what is the benefit of building a C compiler nowadays, and what is interesting about this particular one?

Still not as good as emitting C code in most cases? C code gets optimized using either llvm or any other optimizer so it’s a more portable compile target.

Because compiling to C would be too easy.

I think the biggest benefit of compiling to C is that you can output comments about which C sections correspond to which lines in the higher level code, and then you can use step-through debuggers to see why your emitted code isn't working right.

You don't have to deal with all the idiosyncrasies of C, because you can restrict yourself to a small subset of C that is straightforward and easily understood.


I don't know much about compiler development, but this seems pretty high level to me. Why would I not just compile to C and get almost all the same benefits, except it being small and hackable, but TCC is that too. And if you compile to C you can target even more architectures.

Does compiling to C-- have any benefits compared to compiling equivalent C code (maybe a subset of C)? My guess would be modern C compilers, powered by decades of R&D and programming, would be able to optimize just as well and possibly better.

EDIT: One advantage that comes to my mind is that compiling to C-- will give slightly more power to deal with stack. E.g. implementing exceptions, continuations etc would be simpler. This is possible in C using inline assembly.


I wonder if the author would be surprised by how many language compilers have targeted C for their output.

because there are C compilers available for everything out there.

I thought the principle benefit of compiling to C was the ease of bring up on a new system.

I think it goes to LLVM IR rather than C. It does it's own type inference, so compiling to C after that would preclude many optimizations that it could take advantage of.

If you're going to "beat" C with another language, it will obviously be one that compiles to C.

It's odd to see compilation to C as a main selling point.

That’s more about the compiler than C.

You'd be surprised how much can be optimized even when using the same C compiler.

No header files hell for example.


For one, respected community member pcwalton has argued against compiling to C, citing the difficulty in producing performant, memory-safe output.

For another, from personal experience, I can comment that compiling to C in such a way that doesn't leak abstractions left and right is quite challenging. It's pretty hard to produce memory-safe C, so it's a ton of work, and the payoff is pretty marginal, as the most important platforms already are supported by LLVM.


There are a lot of compilers that target directly C.

Not only that, but you can also use many other C compilers, like Intel's own which AFAIK has some pretty big optimizations for Intel CPUs specifically.

Well, my thoughts are that if a C compiler can do all the heavy lifting I may as well take advantage of that. Transpiling to C also reduces, if not eliminates, any internal recursion in the expression evaluation. You also get decades of optimisations too, although I don't see there being much of that.
next

Legal | privacy