4 ms·
> undefined behavior = the compiler has the right to do wathever it wants It would also be allowed to follow the principle of least surprise. Most instances of
by _pmf_ 10y ago
> undefined behavior = the compiler has the right to do wathever it wants
It would also be allowed to follow the principle of least surprise. Most instances of UB have a specific expected outcome; for signed overflow, one would probably expect the architecture specific signed overflow handling to happen.
It's a bit paradox that some hard errors for which no such expected outcome exists, such as an address violation, can easily be caught by the programmer (SIGSEGV), but errors (UB) for which a specific, sensible reaction exists are not only silently tolerated, but actively exploited when searching optimization.
- wbl 10y agoIt's not actively exploited, just ignored when checking the optimization is valid. Putting values in loops into registers can require making assumptions about different types of pointers pointing to different things.