This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

char should be signed by default


GCC should treat plain char in the same fashion on all types of machines
(by default).

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.

The GNU C compiler supports both dialects; you can specify the signed
dialect with -fsigned-char and the unsigned dialect with
-funsigned-char. However, this leaves open the question of which dialect
to use by default.

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.

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.

A given program is written in one or the other of these two dialects.
The program stands a chance to work on most any machine if it is
compiled with the proper dialect. It is unlikely to work at all if
compiled with the wrong dialect.

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.

Occasionally users write programs intended only for a particular machine
type. On these occasions, the users would benefit if the GNU C compiler
were to support by default the same dialect as the other compilers on
that machine. But such applications are rare. And users writing a
program to run on more than one type of machine cannot possibly benefit
from this kind of compatibility.

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.

(Of course, users strongly concerned about portability should indicate
explicitly whether each char is signed or not. In this way, they write
programs which have the same meaning in both C dialects.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]