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: "'Nick Ing-Simmons'" <nick at ing-simmons dot net>, jamie at shareable dot org,gcc at gcc dot gnu dot org, "'Morten Welinder'" <terra at gnome dot org>
- Date: Fri, 8 Oct 2004 10:20:14 -0700
- Subject: Re: signed vs unsigned pointer warning
- References: <20041008100853.A2207@synopsys.com> <NUTMEGmiU2mdk9tEee90000033d@NUTMEG.CAM.ARTIMI.COM>
I wrote:
> > Here's a bug fix:
> >
> > table_lookup[1U+(unsigned)(c)]
> >
> > Now EOF goes into slot 0.
On Fri, Oct 08, 2004 at 06:12:09PM +0100, Dave Korn wrote:
> Hmm, but only by virtue of integer maths overflow. Wouldn't it be better
> to just leave out the cast in this case and do the sum in signed math?
No. The C standard guarantees that unsigned arithmetic obeys the rules
of arithmetic modulo 2**N, where N is the number of bits. The overflow is
well-defined and is required to yield zero.
Signed math would mishandle the original case, where the original argument
was a signed char with 8th bit set.