how has C bitten you?

Walter Bright bright at dataio.UUCP
Sun Aug 4 00:32:26 AEST 1985


In article <5400010 at prism.UUCP> matt at prism.UUCP writes:
>I sure wish that while the ANSI committee was adding "signed" to the
>language, they had standardized whether the default for "char" was
>signed or unsigned.  As long as compilers have to provide them both
>anyway, what's the harm in choosing one as the default?

The reason why some compilers default to signed chars and others
default to unsigned can be found in the instruction set of the underlying
machine. Some machines support signed chars easier than unsigned ones,
and vice versa. Some examples:

	The 8088 can only sign extend a byte to a word from the AL register,
	whereas a zero extension can cheaply be done from the AL,BL,CL
	or DL register. Thus, most 8088 C compilers default to unsigned
	chars.

	The pdpll, when reading a byte from memory, automatically sign
	extends the byte. Thus, implementing unsigned chars costs an
	extra mask instruction for each char read. Not suprisingly,
	chars default to being signed.

For most applications, it doesn't matter whether a char is signed or
not, and so it is appropriate for the compiler to select that which
can be implemented most efficiently. When it does matter, the programmer
should take care (by explicitly declaring it as signed or unsigned).



More information about the Comp.lang.c mailing list