This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Possible spurious warning for isdigit() under sparc-sun-solaris2.5.1 and egcs 110597?
- To: eisenbud at cs dot swarthmore dot edu
- Subject: Re: Possible spurious warning for isdigit() under sparc-sun-solaris2.5.1 and egcs 110597?
- From: Ian Lance Taylor <ian at cygnus dot com>
- Date: Sun, 9 Nov 1997 12:25:22 -0500
- CC: egcs at cygnus dot com
Date: Sun, 9 Nov 1997 12:13:37 -0500
From: Daniel Eisenbud <eisenbud@cs.swarthmore.edu>
The following macro in <ctype.h> (both in /usr/include, and egcs's fixed
version):
#define isdigit(c) ((__ctype + 1)[c] & _N)
makes egcs -Wall emit a warning that the subscript is a char every time
isdigit is used on a char. First of all, perhaps this is a bug, not a
feature. But it seems like making Wall warn on every use of ischar,
isdigit, etc, is bad. Maybe fixincludes should add a cast? (Excuse me
if this has already been discussed - I have been following the list, but
sometimes intermittently.
ANSI C says that the argument to all these functions must be ``an int,
the value of which is representable as an unsigned char or [...] equal
[to] the value of the macro EOF.''
If your code is passing a char, and char is signed, then your code is
indeed doing something that is worth warning about, since a negative
value for signed char is not representable as unsigned char. This
could catch you if you ever use a machine that uses character values
greater than 127.
In my opinion you should fix your code to include the casts. Or you
shouldn't use -Wall. I think it's reasonable to require casts to
disable warnings.
Adding a cast to unsigned char to isdigit, et. al., would be simply
incorrect, since it would cause the macros to return the wrong value
for EOF.
Ian