This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: signed vs unsigned pointer warning


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]