Hacker News new | ask | show | jobs
by IshKebab 1688 days ago
> To make it clearer, you could imagine an alternate version of C that aborted the program if an integer overflowed. Then there would be no undefined behavior at all - but the optimization is still possible.

The optimisation wouldn't be possible in that case because then the program wouldn't abort when the integer overflowed. It would break the defined behaviour that overflow=abort.

2 comments

This is correct. In the motivating example, it would have to scan the entire list of pointers to see whether it finds a NULL link before it overflows the size counter or not.
Ah, you're completely right, the compiler couldn't hid or assume away the aborts as they would now be part of the spec.