Signed char - What Foolishness Is This!

Jason Zions jason at hpcnoe.UUCP
Sun Oct 19 05:08:03 AEST 1986

jwg at duke.UUCP (Jeffrey William Gillette) /  6:26 am  Oct 16, 1986 /

> 1)      Do other C compilers make 'char' a signed quantity by default?

Oh, let's see. The PDP-11 and VAX chars are signed by default. There are
doubtless many others; I believe 68000 defaults to signed as well.

> 2)      What possible justification is there for this default?

You'll notice in the above list that I mentioned CPU types, rather than
particular compilers. That's because of the answer to your question 2. A
compiler may choose to make chars signed or unsigned depending upon which
is more efficient. chars are indeed arithmetic objects; if they weren't,
you couldn't freely intermix them with integers.

The problem you're running into is an age-old one; the automatic conversion
of a char to an int. If a char is signed, the conversion is a sign-extending
one, resulting in a potentially negative int. If the char is unsigned, the
conversion is (essentially) a bit-field copy, and the resulting int is
always positive.

K&R, chapter 2, page 40:

	The language does not specify whether variables of type *char*
	are signed or unsigned quantities. When a *char* is converted
	to an *int*, can it ever produce a *negative* integer? Unfortunately,
	this varies from machine to machine, reflecting differences in

Have fun; this one bites everyone at least once... I've lost about a pound
of flesh from a sensitive portion of my anatomy from being bitten so often.
This is not an official statement of Hewlett-Packard Corp., and does not 
necessarily reflect the views of HP. It is provided completely without warranty
of any kind. Lawyers take 3d10 damage and roll a saving throw vs. ego attack.

Jason Zions				Hewlett-Packard
Colorado Networks Division		3404 E. Harmony Road
Mail Stop 102				Ft. Collins, CO  80525

More information about the Comp.lang.c mailing list