-Wimplicit-signed-char
Russell King
rmk@arm.linux.org.uk
Mon Apr 24 16:25:00 GMT 2000
Hi,
I'd like to suggest an improvement for GCC.
There appears to be a growing amount of code out there written with such
things as:
char foo = -1;
if (foo == -1) {
bar();
}
or
char ch;
do {
ch = getopt(...);
...
} while (ch != EOF);
The above fragments of code compile cleanly on architectures which default
to signed chars. However, when compiled on an unsigned char defaulting
platform, which is allowed by ANSI and allows these architectures to
enhance performance, although you do get a warning, and the resulting test
fails to work as expected.
It would be useful if people developing portable code (eg, GNU code) which
is intended to be run on many platforms could have a warning flagging this
type of mistake.
To this purpose, can I suggest that a new warning flag is added:
-Wimplicit-signed-char
The rules for generating the warning should be:
(If a variable has been declared using just the "char" type, but without
an explicit "signed" or "unsigned") and
((A negative number is assigned to the variable above) or
(A comparison between the veriable above and a negative number))
I'm currently not sure if -Wall should turn this check on at the moment.
In the interests of getting the code fixed, I would suggest that it is
turned on with -Wall.
_____
|_____| ------------------------------------------------- ---+---+-
| | Russell King rmk@arm.linux.org.uk --- ---
| | | | http://www.arm.linux.org.uk/~rmk/aboutme.html / / |
| +-+-+ --- -+-
/ | THE developer of ARM Linux |+| /|\
/ | | | --- |
+-+-+ ------------------------------------------------- /\\\ |
More information about the Gcc
mailing list