Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!ames!ucbcad!ucbvax!decvax!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: comp.lang.c Subject: Re: is it really necessary for character values to be positive? Message-ID: <598@mcgill-vision.UUCP> Date: Mon, 12-Jan-87 00:54:14 EST Article-I.D.: mcgill-v.598 Posted: Mon Jan 12 00:54:14 1987 Date-Received: Sat, 17-Jan-87 16:39:38 EST References: <39@houligan.UUCP> <289@haddock.UUCP> Organization: McGill University, Montreal Lines: 41 In article <289@haddock.UUCP>, karl@haddock.UUCP (Karl Heuer) writes: > 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. Well. Now, exactly what does it mean to say that @ is negative? Presumably it means that the test below will succeed: char c; /* note: not int */ .... c = '@'; if (c < 0) Now, remember that everybody (K&R and H&S and I hope ANSI) agrees that 'x' is an int, not a char. Notice that you can't make '@' the same thing as what getchar() returns, because the following will fail: char string[something]; .... if (string[subscript] == '@') About the neatest solution I see is to make 'x' have type unsigned char rather than int, at least when there's only one character between quotes (is there any code out there *using* multi-char character constants?). Then we also have to arrange that char and unsigned char are not promoted to int in expressions not involving anything bigger than char. This should make both of these work. Is there anything wrong with changing the type of 'x' literals (and fixing char-only expressions), that is, will it break anything? der Mouse USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse think!mosart!mcgill-vision!mouse Europe: mcvax!decvax!utcsri!mcgill-vision!mouse ARPAnet: think!mosart!mcgill-vision!mouse@harvard.harvard.edu