This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: signed vs unsigned pointer warning
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Dave Korn <dk at artimi dot com>
- Cc: "'Andreas Schwab'" <schwab at suse dot de>,"'Morten Welinder'" <terra at gnome dot org>, gcc at gcc dot gnu dot org
- Date: Thu, 23 Sep 2004 09:11:18 -0700
- Subject: Re: signed vs unsigned pointer warning
- References: <jeu0tqhsre.fsf@sykes.suse.de> <NUTMEGL3tAkqzwUUAPk00000053@NUTMEG.CAM.ARTIMI.COM>
On Thu, Sep 23, 2004 at 12:35:22PM +0100, Dave Korn wrote:
> > "Dave Korn" writes:
> >
> > > Which I don't think you can, since you can't store negative numbers
> > > in an unsigned type.
> >
> > Actually you can, due to the modulo behaviour of unsigned integers.
> >
> > Andreas.
>
> Well, yes, it is physically possible, but it's a kind of type-punning, it
> defies the aliasing rules, and we get into some very deeply
> language-lawyerly issues here, but it's not a valid representation IIUIC and
> therefore invokes undefined behaviour in many circumstances.
The C aliasing rules specifically bless accessing ints as unsigneds, and,
more generally, punning accesses between any type and the unsigned version
of that type.