3 ms·
One piece of this is probably that compilers competing to generate the best code have increasingly incorporated understanding of undefined behavior into their o
by codys 6y ago
One piece of this is probably that compilers competing to generate the best code have increasingly incorporated understanding of undefined behavior into their optimizers, leading to things that were previously undefined but happened to behave in some particular way to instead behave in ways that break programs using undefined behavior.
Compilers incorporate inferences that can be made by assuming UB doesn't occur into their optimization because it improves code generation of correct programs.
- ryandrake 6y agoThis is one of the humps that C programmers eventually just need to get past: That UB means literally anything is possible[1]. Not just what you currently see happening with the current version of your compiler on your current platform. Anything! We've all run into a few programmers who would insist that their particular invocation of undefined behavior was fine, because as you said, it "behaves in some particular way". Now that we have more aggressively optimizing compilers we don't run into those folks so much anymore. I wouldn't say it's a minuscule factor in my daily work, as OP put it, but it's not something to agonize about if you stay mindful of avoiding common undefined behavior pitfalls. It would be very helpful if compilers were better about warning you when you're venturing into UB, but that's a different topic. 1: You can even get the shirt: https://teespring.com/shop/undefined-behavior-shirt https://teespring.com/shop/undefined-behavior-shirt
- perl4ever 6y ago>That UB means literally anything is possible Many people say this but nobody "literally" believes it. It's a way of expressing the righteous dominance of one person or group's attitude towards reasonableness over another's. In a way that forestalls argument. "Literally anything" could literally mean global thermonuclear war.