Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!decvax!ima!haddock!karl From: karl@haddock.UUCP (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: is it really necessary for character values to be positive? Message-ID: <293@haddock.UUCP> Date: Fri, 9-Jan-87 03:15:09 EST Article-I.D.: haddock.293 Posted: Fri Jan 9 03:15:09 1987 Date-Received: Fri, 9-Jan-87 21:37:58 EST References: <39@houligan.UUCP> <289@haddock.UUCP> <548@brl-sem.ARPA> Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer) Organization: Interactive Systems, Boston Lines: 27 In article <548@brl-sem.ARPA> ron@brl-sem.ARPA (Ron Natalie) writes: >In article <289@haddock.UUCP>, karl@haddock.UUCP (Karl Heuer) writes: >> In article <39@houligan.UUCP> dave@murphy.UUCP writes: >> >Summary: invent an 8-bit character set and let some of them be negative >> >> 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 == '@') ... } > >Getchar returns int. The int has a character in it. Before trying to >use it as such, you ought to either place it back into a character >variable explicitly or use a cast to char... > > main() { int c; ... c = getchar(); ... if ((char) c == '@') ... } That's one way to "fix" the problem, but the construct I wrote is valid by current standards and is a common idiom. I don't think programmers would like having to cast* the result of getchar() back into char before using it! Your suggestion does make sense logically, though, and I think it supports my contention that making getchar() an int function was a mistake in the first place.** Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint *Of course, the cast is done *after* testing for EOF. **I do have what I think is a better idea, but I'm not going to describe it in this posting. Anyway, it's too late to change getchar() now.