From: jjf AT bcs DOT org DOT uk (J. J. Farrell) Subject: Re: some unusual errors 24 Sep 1998 06:09:19 -0700 Message-ID: <199809232120.OAA04855.cygnus.gnu-win32@aleph.ssd.hal.com> References: <199809222007 DOT QAA24654 AT venus DOT solidum DOT com> Content-Type: text To: mcr AT solidum DOT com (Michael Richardson) Cc: gnu-win32 AT cygnus DOT com > From: Michael Richardson > > > >>>>> "Peter" == Peter Dalgaard BSA

writes: > > Peter> Michael Richardson writes: > > >> >> strtod.c:1239: warning: subscript has type `char' >> which confuses > >> me. What, if not "char" should isspace() take??? > >> > Michael> As all is functions it takes an *int* or *unsigned char* ! > >> > Michael> int isalnum (int c); int isalpha (int c); > >> Why would you say "unsigned char"?? It says "int" to me. So, a > >> signed char should promote to int just fine. > > Peter> ...with everything above 127 mapping to negative numbers! > > Yes. That's my problem. > The macro is wrong: it should behave in the same way as a prototyped > function. I agree entirely with what you say, but I think it may not be what you mean! The only way in which the function version will behave differently from the macro version is that the function version won't give you the spurious warning message. If you pass a signed char which contains a negative value (top bit set) other than EOF to any of the ctype macros or functions, you will get undefined behaviour - it may do what you want by luck, or it may crash your program or do anything else it fancies. If you can be certain that the values in your signed chars are between 0 and UCHAR_MAX, there's no problem passing those signed chars to a ctype function - but you have to put up with the spurious warning in this implementation. If you can't be certain of that, you must do something to make certain - either check their value before calling is*(), or access them as unsigned if that's appropriate. The most portable fix to your example bit of code would be for(s = s00; isspace(*(unsigned char*)s); s++) or just declare s as in the first place. [ Casting the char itself to unsigned is not a portable answer to this since it will change the bit pattern on a 1's complement machine; probably not what is wanted. ] - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".