linuxppc

Michael Meissner meissner@cygnus.com
Sun Nov 12 17:26:00 GMT 2000


On Sun, Nov 12, 2000 at 03:58:30PM -0500, Magnus Ågren wrote:
> Hello
> 
> I don't know if it is a bug but when i compile a program on linuxppc
> that make a comparison like
> 
> char c;
> ...
> ...
> 
> if (c < 0)
> {
> ....
> }
> 
> 
> I get the following warning: comparison is always false due to limited
> range of data type.
> 
> So I have to use the -fsigned-char flag when compiling. This is not the
> case when compiling on linux intel, shouldn't it be the same???

As Alex said, it is up to the ABI to determine whether char is treated as
"signed char" or "unsigned char".  If it is not specified, it is treated as
"don't char" (this pun in fact was used in the X3J11 standards meeting, when
talking about this very issue).

In particular, the System V machine supplement for the PowerPC (which is the
guiding ABI for Linux on PowerPC machines) explicitly says that char types
without a signed or unsigned specifier promote as unsigned.

IMHO, the default promotion of char (due to the fact that the PDP-11 did it
that way by default) as signed is a historical travesty, since it meant you
couldn't use "char" to hold normal character data types, except in the US with
7 bit ASCII (ie, you couldn't use it for the 8 bit character set).  As I
recall, when asked if he could go back in time and change one thing, Deniis
Ritchie said he would make chars unsigned by default (and FYI, Thompson would
have gone back and spell the creat system call with a trailing e).

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


More information about the Gcc-bugs mailing list