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

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



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.
(mksh’s internal guaranteed-to-wrap-around signed 32-bit integer
arithmetics is implemented using only C unsigned integer types,
since a while, due to this. Yes, speed hit, especially since the
CPUs (except DSPs, possibly) could all do this correctly.)

bye,
//mirabilos
-- 
In traditional syntax ' is ignored, but in c99 everything between two ' is
handled as character constant.  Therefore you cannot use ' in a preproces-
sing file in c99 mode.	-- Ragge
No faith left in ISO C99, undefined behaviour, etc.


Reply to: