signed vs unsigned pointer warning

Dave Korn dk@artimi.com
Fri Oct 8 18:15:00 GMT 2004


> -----Original Message-----
> From: Joe Buck  
> Sent: 08 October 2004 18:09
> To: Nick Ing-Simmons; jamie@shareable.org; gcc@gcc.gnu.org; 
> 'Morten Welinder'; Dave Korn
> Subject: Re: signed vs unsigned pointer warning
> 
> On Fri, Oct 08, 2004 at 12:26:35PM -0400, Paul Jarc wrote:
> > Joe Buck <Joe.Buck@synopsys.COM> wrote:
> > > Why can't an implementation define isxxx(c) to return 
> something like
> > >     table_lookup[(unsigned)(c)]
> > > ?
> > 
> > Assuming EOF==-1, that fails to distinguish between EOF and 
> character
> > 255 (as does the 384-element table in the case where a 
> signed char is
> > passed).  The ctype macros are supposed to accept EOF as well as
> > unsigned char values.
> 
> No, (unsigned)-1 does not turn into 255, it turns into a very large
> number.  You cannot store EOF in a char.  

  Of course, isXXXX functions do take an int argument, which can indeed
store EOF.

> Here's a bug fix:
> 
> 	 table_lookup[1U+(unsigned)(c)]
> 
> Now EOF goes into slot 0.

  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?

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Gcc mailing list