Embed Notice
HTML Code
Corresponding Notice
- Embed this notice@SuperDicq @iron_bug @diresock
> However, we tend to want the most optimized solution.
"I can give you the answer as fast as you want, as long as it doesn't have to be correct."
I mean, everyone wants their code to run fast, but they want it to be their code. You don't want something the compiler hallucinated that may or may not resemble what you wrote. Since the 70s, one of the points stressed about C was that you could tell what it was going to do: no fuzziness, you can basically see the instructions the compiler will emit. So gcc emits some SIMD stuff when it spots your for loop adding two arrays together, that's fine, it's emitting code that behaves the same as what you wrote, but changing printf() to puts() or optimizing away an infinite loop is way beyond the pale.
You end up coming across a lot of "No, goddammit, do what I wrote" directives in code. `___this_is_actually_used___`, people introducing side effects to fool the compiler into emitting code that executes their loops, a sea of #defines and #ifdefs and underscore-rich symbols. "No, actually inline this, I really mean it this time, this function is only called once and there's no reason not to inline it." 4kB of `-fstop-doing-retarded-shit` passed to the compiler. (I made up the option name but try compiling qt4 some time if you want to see a compiler invocation that is longer than the text of the file it's compiling.)
> they are technically correct that skipping the if statement is valid because according to C integer overflow is considered "undefined behavior",
This is not remotely the case. "The spec says that it won't say what to do about this" does not mean "It's safe to ignore" and it's no excuse to write a bad compiler.
> It's probably better if the compiler shows a warning and executes it anyway or something like that.
A warning would be fine. "If someone digs a signed magnitude machine out of a museum or maybe someone writes a C compiler for old-timey analog computers, this code probably won't work the way you expect." I mean, "x+100" even handles one's complement.