This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Do C++ signed types have modulo semantics?
- From: Michael Veksler <VEKSLER at il dot ibm dot com>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: gcc mailing list <gcc at gcc dot gnu dot org>, Nathan Sidwell <nathan at codesourcery dot com>, Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Tue, 28 Jun 2005 18:30:40 +0300
- Subject: Re: Do C++ signed types have modulo semantics?
Gabriel Dos Reis wrote on 28/06/2005 17:12:43:
> Andrew Pinski <pinskia@physics.uc.edu> 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