Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.unix-wizards,net.lang.c Subject: Re: Why chars unsigned on 3B? Message-ID: <3947@utzoo.UUCP> Date: Fri, 8-Jun-84 17:04:16 EDT Article-I.D.: utzoo.3947 Posted: Fri Jun 8 17:04:16 1984 Date-Received: Fri, 8-Jun-84 17:04:16 EDT References: <310@basser.SUN>, <479@wjh12.UUCP> Organization: U of Toronto Zoology Lines: 34 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