Gabriel Dos Reis wrote on 28/06/2005 17:12:43:
> Andrew Pinski <[EMAIL PROTECTED]> writes:
>
> | On Jun 28, 2005, at 9:58 AM, Gabriel Dos Reis wrote:
> |
> | > Notice that in your rendition you're assuming that you can convert
any
> | > unsigned value > INT_MAX to a int without invoking undefined
behaviour.
> |
> |
> |
> | If you read Nathan's mail correctly, the cast is implementation defined
> | and not undefined behavior so your argument does not work.
>
> I stand corrected!
>
So what does gcc gives for (int) (MAX_INT+1U)?
Maybe it is constrained such that
(int)(unsigned)a == a
For 1's complement the reverse seems to be incorrect:
unsigned a= 0xFFFFFFFF; // or was it 0x80000000?
assert((unsigned)(int)a == a); // may fail
This is because as far as I remember 0xFFFFFFFF is interpreted
as -0, which then cast to unsigned as 0x00000000.
This behavior seems to be undocumented (a documentation PR?).
Michael