signed vs unsigned pointer warning
Joe Buck
Joe.Buck@synopsys.COM
Fri Oct 8 18:22:00 GMT 2004
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.
More information about the Gcc
mailing list