qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "M. Warner Losh" <imp@bsdimp.com>
To: qemu-devel@nongnu.org, schwab@suse.de
Subject: Re: [Qemu-devel] [PATCH] Fix char signedness
Date: Fri, 27 Oct 2006 12:23:11 -0600 (MDT)	[thread overview]
Message-ID: <20061027.122311.-365734984.imp@bsdimp.com> (raw)
In-Reply-To: <jeac3hd4jv.fsf@sykes.suse.de>

In message: <jeac3hd4jv.fsf@sykes.suse.de>
            Andreas Schwab <schwab@suse.de> writes:
: Johannes Schindelin <Johannes.Schindelin@gmx.de> 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
implementor:

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
chars:

% 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.

Warner

  reply	other threads:[~2006-10-27 18:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-27 17:07 [Qemu-devel] [PATCH] Fix char signedness Andreas Schwab
2006-10-27 17:40 ` Johannes Schindelin
2006-10-27 17:54   ` andrzej zaborowski
2006-10-27 17:58   ` Andreas Schwab
2006-10-27 18:23     ` M. Warner Losh [this message]
2006-10-28 10:46       ` Martin Guy
2006-10-28 19:04         ` Rob Landley
2006-10-27 22:57     ` Johannes Schindelin
2006-10-27 23:09       ` Paul Brook
2006-10-28 18:58         ` Rob Landley
2006-10-27 23:12       ` Thiemo Seufer
2006-10-27 23:17       ` M. Warner Losh
2006-10-28 10:14       ` Laurent Desnogues

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061027.122311.-365734984.imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=qemu-devel@nongnu.org \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).