[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Fix char signedness

From: M. Warner Losh
Subject: Re: [Qemu-devel] [PATCH] Fix char signedness
Date: Fri, 27 Oct 2006 12:23:11 -0600 (MDT)

In message: <address@hidden>
            Andreas Schwab <address@hidden> writes:
: Johannes Schindelin <address@hidden> writes:
: > It has been a really long time I have been working on a broken system that 
: > did not default to "signed".
: The only thing that is broken is your knowlege of C.

gcc on ARM systems default to unsigned.  The C standard specifically
states that char is either signed or unsigned at the whim of the

Section 6.2.5 para 15:

       [#15] The three types char, signed char, and  unsigned  char
       are   collectively   called   the   character   types.   The
       implementation shall define char to  have  the  same  range,
       representation,  and  behavior  as  either  signed  char  or
       unsigned char.30)
       30)CHAR_MIN, defined in <limits.h>, will  have  one  of  the
          values   0   or  SCHAR_MIN,  and  this  can  be  used  to
          distinguish the two options.  Irrespective of the  choice
          made,  char  is a separate type from the other two and is
          not compatible with either.

I just confirmed that gcc on arm does indeed default to unsigned

% cat xxx.c
signed char cs = -1;
unsigned char cu = -1;
char c = -1;

void foo()
        int i = 0;
        if (cs < 0) i++;
        if (cu < 0) i++;
        if (c < 0) i++;
%  gcc -v
Using built-in specs.
Configured with: FreeBSD/arm system compiler
Thread model: posix
gcc version 3.4.4 [FreeBSD] 20050518
% gcc -W -c xxx.c
xxx.c: In function `foo':
xxx.c:9: warning: comparison is always false due to limited range of data type
xxx.c:10: warning: comparison is always false due to limited range of data type

Note: line 10 is the naked char.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]