Why chars unsigned on 3B?

Henry Spencer henry at utzoo.UUCP
Sat Jun 9 07:04:16 AEST 1984


Sam Kendall asks:

   Is it true what I have heard, there are instructions on the 3B to
   implement signed chars easily?  If so, why are chars unsigned in C?

It also, almost certainly, has instructions to implement unsigned
chars easily.  It is fashionable nowadays to provide both.  Thus the
C implementor has to choose:  does he do the clean thing and make the
chars unsigned, or does he opt for maximum compatibility at the cost
of perpetuating a dreadful botch that was an accidental side effect
of the PDP11 design?  Clearly the compiler implementor for the 3B did
the right thing and made chars unsigned.  Please note that sections 4
and 6.1 of the C Reference Manual say, in so many words:

	Objects declared as characters (char) are large enough to
	store any member of the implementation's character set, and
	if a genuine character from that character set is stored in
	a character variable, its value is equivalent to the integer
	code for that character.  Other quantities may be stored into
	character variables, but the implementation is machine-dependent.

	...

	Whether or not sign-extension occurs for characters is machine-
	dependent, [although] it is guaranteed that a member of the
	standard character set is non-negative.

Dennis Ritchie has been heard to say [forgive me, Dennis, if I'm
remembering this wrong] that the signedness of char on the 11 was
definitely a mistake, although hard to avoid given the way the 11
does byte moves.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.unix.wizards mailing list