[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Having fun with the following C code (UB)



On 2014-04-10 11:48:44 +0000, Thorsten Glaser wrote:
> Ian Jackson dixit:
> 
> >> 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.
> 
> And GCC is a repeat offender which actually does do that.

If you don't like that, you should use the -fwrapv option.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Reply to: