Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cuae2!gatech!akgua!codas!peora!ucf-cs.ucf.edu!novavax!houligan!dave@murphy.UUCP From: dave@murphy.UUCP Newsgroups: comp.lang.c Subject: Re: is it really necessary for character values to be positive? Message-ID: <44@houligan.UUCP> Date: Wed, 14-Jan-87 12:54:10 EST Article-I.D.: houligan.44 Posted: Wed Jan 14 12:54:10 1987 Date-Received: Mon, 19-Jan-87 06:15:59 EST Organization: Gould Electronics, Ft. Lauderdale, Florida. Lines: 44 Summary: does EOF have to be -1? In article <289@haddock.UUCP>, karl@haddock.ISC.COM.UUCP (Karl Heuer) types (in response to an earlier article that I wrote): >Suppose I am using such a system, and one of the characters -- call it '@' -- >has a negative value. The following program will not work: > main() { int c; ... c = getchar(); ... if (c == '@') ... } >Note that getchar() returns an UNSIGNED char on success; this is to guarantee >that none of them compare equal to EOF. Thus, any printing character that I >want to enclose in single quotes had better be positive, or it becomes VERY >awkward to use. Thanks for pointing this out, but I don't see where it should cause a major problem. Assuming that the character set in use doesn't take up the entire range of int values, all that is necessary is to pick a value for EOF that doesn't correspond to any character value. (Newcomers: keep in mind that the return value of getchar and getc is defined as being an int, not a char, even though it is often treated like a char.) This way, getchar can return a possibly negative value, and EOF won't collide with any legit character value. Would defining EOF to be something other than -1 cause a problem? I don't think so. K&R says, on p. 144: "The standard library defines the symbolic constant EOF to be -1 (with a #define in the file 'stdio.h'), but tests should be written in terms of EOF, not -1, so as to be independent of the specific value." I don't this is a situation like with NULL where the actual value has a special meaning in the language definition, so I don't see why it couldn't be changed. People who are testing for -1 or for a negative value instead of using EOF deserve whatever they get. If anyone knows of any reason why the value of EOF can't be implementation- specific, I'd like to hear about it. --- "I used to be able to sing the blues, but now I have too much money." -- Bruce Dickinson Dave Cornutt, Gould Computer Systems, Ft. Lauderdale, FL UUCP: ...!{sun,pur-ee,brl-bmd,bcopen}!gould!dcornutt or ...!{ucf-cs,allegra,codas}!novavax!houligan!dcornutt ARPA: dcornutt@gswd-vms.arpa (I'm not sure how well this works) "The opinions expressed herein are not necessarily those of my employer, not necessarily mine, and probably not necessary."