is it really necessary for character values to be positive?

Ron Natalie <ron> ron at brl-sem.ARPA
Wed Dec 31 04:12:38 AEST 1986


In article <289 at haddock.UUCP>, karl at haddock.UUCP (Karl Heuer) writes:
> In article <39 at houligan.UUCP> dave at murphy.UUCP writes:
> >Summary: invent an 8-bit character set and then 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 == '@') ... }



More information about the Comp.lang.c mailing list