4 ms·
The reason that these behaviors are undefined typically is that the compiler cannot prove whether or not a program will execute undefined behavior, and needing
by readams 8y ago
The reason that these behaviors are undefined typically is that the compiler cannot prove whether or not a program will execute undefined behavior, and needing to account for it would lead to less efficient code. For example if (x+1 > x) can be simplified to if (true) for signed integers only because signed overflow is undefined.
That said, there is UBSan, which is a runtime checker for undefined behavior that can help you to identify if your code is depending on some undefined result.