Re: Having fun with the following C code (UB)
Wouter Verhelst writes ("Re: Having fun with the following C code (UB)"):
> Yes; the standard does this to allow for machine architectures which do
> not use two's complement to store negative values. I did mention that
> assumption in my previous mail.
>
> If the architecture uses two's complement, however, then the code is
> correct.
Unfortunately adversarial optimisation by modern compilers means that
this kind of reasoning is no longer valid.
The compiler might easily see that your code unconditionally performs
a computation with undefined behaviour, and delete it.
Ian.
Reply to: