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

This is mostly only true for modern optimising C compilers. If you take a simple C compiler from the 90's, or disable optimisations in a modern compiler, there's a near 1:1 relationship between the C code and compiler output.


sort by: page size:

Not necessarily true, although C compilers are usually very good.

That’s more about the compiler than C.

Are you arguing that e.g. Turbo C and friends from the 80s were higher quality than modern C compilers?

Unless you’ve written a modern, optimizing C/C++ compiler, you have absolutely no idea what kind of machine code a complex program is going to spit out. It’s not 1972 anymore, and C code is no longer particularly close to the metal. It hasn’t been for some time.

Isn't it that if you write standard compliant C code, much less compilers come into the picture ;)

C compiler performance in the 80's for home micros was so bad, that functions were basically naked entry points to full inline Assembly.

And here we are now discussing how good modern C compilers are.

If there isn't the willingness to spend the money to optimize performance, of course it won't improve.


Even with C it only looks like it, if one sticks mainly with a specific compiler and OS.

Yesteryear's C compilers weren't great, optimization-wise. But anything remotely modern would just brute force its way through a DOS-era program, well optimized or not.

So, what you're saying is that C is (usually) compiled?

Or that your compiler produces code equivalent to the (proven) correct C.

Well we disagree vehemently: writing clean C code that compiles with any ANSI C compiler is pretty damn easy. Take BIND for example, a non-trivial piece of software which compiles with any compiler.

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.


Can you really map gcc output to your C code ? With all the optimizations (CF, CSE, RA, ...) the assembly code can vary dramatically (from what I recall from compilation classes at least)

The classic C compilers were known for producing horribly unoptimized code.

It took many years of compiler progress to change C into the performant language we all know and love/hate today.


Their comment makes sense if you interpret "the C compiler" to mean "mainstream C compilers that 99% people use in production" or even just "gcc and clang".

We're talking about concrete things in the real world here, not philosophizing about the language spec.


C compilers

Also many that praise C's performace, tend to forget that once upon a time, hobby Z80, 6052, 80x86, 68000 programmers in home micros could write better code than C compilers were able to generate.

So there are a few decades of engineering time spent improving code generation of C compilers.


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.


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

Legal | privacy