3 ms·
> It's actually an interesting example where undefined behavior allowed compiler optimization That is literally reason why any behavior is considered undefined
by Noughmad 5y ago
> It's actually an interesting example where undefined behavior allowed compiler optimization
That is literally reason why any behavior is considered undefined. So that the compiler can skip checks to produce better optimized code.
- secondcoming 5y agoAnd so you get an optimal, but broken, program. This helps nobody.
- saagarjha 5y agoActually, many instances of undefined behavior are born out of a desire for portability. Some processors will fault on both of those and the standard wants to be inclusive of those behaviors. Compilers happen to be able to use the definition of undefined behavior to also optimize code, but the concept is born out of practicality.