3 ms·
I don't know, but I would dearly love to use a compiler that does that.
by iainmerrick 9y ago
I don't know, but I would dearly love to use a compiler that does that.
- gumby 9y ago> I don't know, but I would dearly love to use a compiler that does that. Well you're in luck, since gcc -Werror when used with many of its -W flags will do precisely that. You guys should read the minutes of committee discussions and position papers. "undefined behavior" is not something introduced to make programmers' lives hard! Also look at IEEE734 which does define things to an incredible degree -- it's extremely hard to use (as it needed to be!). It's one of the very best standards of all time, and still has, yes, undefined behavior.
- derefr 9y ago> Well you're in luck, since gcc -Werror when used with many of its -W flags will do precisely that. That's not lucky; I'd argue it's the opposite. An ecosystem built around compilers that default to not using -Werror (or rather: `-Werror=pedantic -pedantic-errors`) is an ecosystem that encourages people to write code that relies on the optimizations compilers make in response to undefined behavior. Which, undoubtedly, "makes [maintenance] programmers' lives hard," when they change one little thing and suddenly the code gets 10x slower because now e.g. a dead loop isn't being elided. If all compilers defaulted to something like `-Werror=pedantic -pedantic-errors`—and it was highly discouraged to turn those flags off—then jumping in to contribute to a portable, sprawling codebase would be infinitely simpler, because the codebase would have been written in a far more rigorous way up to that point. Sunlight is the best disinfectant—so why do we allow our compiler-vendors to default the lights to off?
- iainmerrick 9y agoAmen! I'm not a big Go fan but Go definitely has the better approach here.
- iainmerrick 9y agoTo clarify, it's not actually undefined behavior per se that I'm complaining about, it's the modern trend of highly optimizing compilers which take undefined behavior as an excuse to do all sorts of ridiculous things to your code. "You may have thought you were checking for overflow here, but technically speaking the result of that operation could be undefined, therefore this code could do literally anything, or nothing. So I'll just remove it all. Congratulations, now it runs faster!" I honestly hadn't realized that was a controversial view. Doesn't almost everyone dislike that? Are there a lot of C programmers who are happy to accept that risk in exchange for slightly better optimization?