On Tue, 2007-01-23 at 23:19 -0600, [EMAIL PROTECTED] wrote:
> GCC should treat plain char in the same fashion on all types of machines
> (by default).

No, no, no.  It is up to the ABI what char is.

> The ISO C standard leaves it up to the implementation whether a char
> declared plain char is signed or not. This in effect creates two
> alternative dialects of C.

So ... char is seperate type from unsigned char and signed char in C and
C++ anyways.


> The preferred dialect makes plain char signed, because this is simplest.
> Since int is the same as signed int, short is the same as signed short,
> etc., it is cleanest for char to be the same.

No, no.

> Some computer manufacturers have published Application Binary Interface
> standards which specify that plain char should be unsigned. It is a
> mistake, however, to say anything about this issue in an ABI. This is
> because the handling of plain char distinguishes two dialects of C. Both
> dialects are meaningful on every type of machine. Whether a particular
> object file was compiled using signed char or unsigned is of no concern
> to other object files, even if they access the same chars in the same
> data structures.

No it is not.  The reason is for an example on PPC, there is no signed
extended byte loads, only unsigned.  There is a reason why it is
unsigned on those targets.

> Many users appreciate the GNU C compiler because it provides an
> environment that is uniform across machines. These users would be
> inconvenienced if the compiler treated plain char differently on certain
> machines.

So don't depend on this behavior.  There are plenty of implementation
details.

> There are some arguments for making char unsigned by default on all
> machines. If, for example, this becomes a universal de facto standard,
> it would make sense for GCC to go along with it. This is something to be
> considered in the future.

No, no, no.  GCC cannot change right now, as it would change the ABI.
If you don't believe me, try this program with/without -fsigned-char
and -funsigned-char:

static inline int f(int a)
{
  return a==0xFF;
}

int g(char *b)
{
  return f(*b);
}

---------------
You will see with -fsigned-char, we get 0; with -funsigned-char, we
compare to *(unsigned char*)b 0xFF

-- Pinski

Reply via email to