Signed char - What Foolishness Is This!

Ken Thompson thomps at gitpyr.gatech.EDU
Sat Oct 18 12:08:01 AEST 1986


In article <8719 at duke.duke.UUCP>, jwg at duke.UUCP (Jeffrey William Gillette) writes:
> []
> 1)      Do other C compilers make 'char' a signed quantity by default?

I use a Masscomp system compatible with System V and BSD 4.2 which
has signed characters by default. I find this very annoying when
porting software from machines with the opposite convention but
it causes no problem with code written for this machine.
> 
> 2)      What possible justification is there for this default?  Is not
> 'char' primarily a logical (as opposed to mathematical) quantity?  What
> I mean is, what is the definition of a negative 'a'?  I can understand 
> the desirability of allowing 'signed char' for gonzo programmers who
> won't use 'short', or who want to risk future compatibility of their
> code on the bet that useful characters will always remain 7-bit entities.
> 
I see no justification for signed characters and the concept of a signed
character is somewhat strange. The problem arises because chars used in
an expression in C are automatically converted to type int. Signed
characters come about when the conversion is made from a char which is
an 8 bit quantity to an int which is 16 bits or larger. I do not know
of any C compilers which actually view a char as an 8 bit signed entity.
Instead the char becomes negative to to sign extension during conversion
to int.

-- 
Ken Thompson  Phone : (404) 894-7089
Georgia Tech Research Institute
Georgia Insitute of Technology, Atlanta Georgia, 30332
...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!thomps



More information about the Comp.lang.c mailing list