This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
-Wimplicit-signed-char
- To: gcc at gcc dot gnu dot org
- Subject: -Wimplicit-signed-char
- From: Russell King <rmk at arm dot linux dot org dot uk>
- Date: Tue, 25 Apr 2000 00:20:21 +0100 (BST)
- Cc: philb at gnu dot org
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 |+| /|\
/ | | | --- |
+-+-+ ------------------------------------------------- /\\\ |