Hacker News new | past | comments | ask | show | jobs | submit login

I use gcc for code gen.

The idea to use undefined behavior for optimization is really terrible. Somehow they forget this is engineering project, not in researching. Breaking existing code costs a lot of time and money.

By the way, I don't see their optimization has any impact on the real project I am working on (highly cpu intensive).




"The idea to use undefined behavior for optimization is really terrible. Somehow they forget this is engineering project, not in researching. Breaking existing code costs a lot of time and money."

Saying that using undefined behavior for optimization is really terrible is living in a pipe dream if you code in C at all. No performant C compiler does not use undefined behavior to optimize it's resultant code. In fact, GCC does a fair amount of this too.

The real value in using undefined behavior to optimize code is that it leads to a fair amount of layering of optimizations. And the real world tests so a significant improvement in program running speed because of the interaction of optimizations.

The real problem is that most C programmers expect far more defined behavior than the standard actually gives. For a long explanation and lots of examples of this, see the series of blog posts at: http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

BTW, breaking existing code happens all the time with new compiler version releases with LLVM or GCC.

A side note on GCC: back in school we actually had very simple programs that used only STL data structures (all calls being legal according to the lib specs) that would cause seg faults with certain levels of optimizations in GCC. What's worse: it didn't happen in the previous major X.Y version (i.e. the difference between 4.2 and 4.1.) But even on the breaking build it worked with -O1 but not any higher. That's inconsistent behavior in optimizations if I've ever seen it. But to be fair to the compiler: it's likely that the STL made assumptions that you technically can't make according to the C spec. Just like the OP's code. I love Ruby, but using MRI as an example of code that is a correct program is rather extreme. MRI makes tons of assumptions that often lead to noticeable bugs in the interpreter.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: