This is the mail archive of the gcc-patches@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]

Re: Patch: Add TOUPPER/TOLOWER to system.h and clean up ctype stuff


"Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> said:
>  > From: Gavin Romig-Koch <gavin@cygnus.com>
>  > Richard Henderson writes:

>  >  > On Mon, Sep 13, 1999 at 11:55:14AM -0400, Kaveh R. Ghazi wrote:
>  >  > > Because if the parameter is an int you can't distinguish EOF.
>  >  > > So the cast is only valid if the parameter is a char.

>  >  > I thought of an ugly way to do this --

>  >  > #define DOIT(CH) doit(sizeof(CH) == 1 ? (int)(unsigned char)(CH) : (int)(CH))

>  > Less ugly (my opinion):

>  >   #define DOIT(CH) doit((CH) == EOF ? (int)CH : (int)(unsigned char)(CH))

>  > along with a comment explaining what's going.
>  >                                                    -gavin...
> 
> 	I think the above will do the wrong thing if CH is a char and
> is equal to 255 (-1 when signed, == EOF.)  That is a printable
> character and depending on the locale, may or may not be alphabetic.
> (Right?)

A signed char, cast to unsigned char and then to int can't give you -1.
Unless you have _real_ weird characters, i.e. char == int.

> Since sizeof char might not be one (e.g. c4x), maybe the following is
> best:

According to ANSI C, sizeof(char) == 1, by definition. Or am I missing
something here?
-- 
Dr. Horst H. von Brand                       mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513


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