[cfe-users] Weird optimization
artem.alimarin at gmail.com
Mon Feb 23 03:22:41 PST 2015
Yes, thanks. nasal demons, indeed. I forgot that the signed integer
overflow causes undefined behavior unlike unsigned integer overflow,
which causes wrap around.
return (long)(0ul - (unsigned long)x) > 0;
does what I want.
I am impressed by clang's ability to use this undefinedness to enable
optimizations like (-x) > 0 to x < 0, which seems to be valid for all
On 23-2-2015 9:44, Csaba Raduly wrote:
> cast to an unsigned type to negate
> this value to itself
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 362 bytes
Desc: not available
More information about the cfe-users