Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!gatech!akgua!codas!peora!ucf-cs!novavax!houligan!dave@murphy.UUCP From: dave@murphy.UUCP (H. Munster) Newsgroups: net.lang.c Subject: Re: signed char Message-ID: <140@houligan.UUCP> Date: Wed, 29-Oct-86 16:41:33 EST Article-I.D.: houligan.140 Posted: Wed Oct 29 16:41:33 1986 Date-Received: Fri, 31-Oct-86 13:38:48 EST Organization: Gould Electronics, Ft. Lauderdale, Florida. Lines: 36 Signed char exists because, on the PDP-11 (which is where one of the first C compilers was implemented), it's more efficient to treat them as signed. (The default for loading a byte is to sign-extend it, and if you don't want the sign you have to mask it off, which takes an extra instruction.) K&R states on p. 183 that the implementation may treat characters as either signed or unsigned. (However, it also states that a member of the "standard" character set should be represented as a non-negative quantity. The def- inition of the term "standard" is, of course, open to interpretation and flaming.) Unless your compiler has an "unsigned char" type, and you use it, it's kind of dangerous to rely on the sign of a char. Probably someone should have thought of inventing a "signed char" type earlier, but that's life. Actually, I believe most machines that C exists on treat chars as unsigned. On the Gould UTX compiler, the default is to treat chars not explicitly declared unsigned as signed. This is so that anything that you might port over from a PDP-11 will work (apparently it made porting of some things easier when UN*X was originally ported to these machines). However, there is a compiler option that will make all chars unsigned, so if you're porting something from a VAX, you can have it that way too. (Actually, the most efficient mode is the all-unsigned mode, so the sense of the option should probably be reversed.) Incidentally, I am one of those cretins that sometimes uses "unsigned char" instead of "unsigned short"; I have an application where I save over 2M of memory by doing that. I have never found a use for signed chars. --- It's been said by many a wise philosopher that when you die and your soul goes to its final resting place, it has to make a connection in Atlanta. Dave Cornutt, Gould Computer Systems, Ft. Lauderdale, FL UUCP: ...{sun,pur-ee,brl-bmd}!gould!dcornutt or ...!ucf-cs!novavax!houligan!dcornutt ARPA: wait a minute, I've almost got it... "The opinions expressed herein are not necessarily those of my employer, not necessarily mine, and probably not necessary."