is it really necessary for character values to be positive?

Karl Heuer karl at haddock.UUCP
Thu Dec 25 07:05:18 AEST 1986


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 == '@') ... }
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.

Please don't suggest that getchar() should return a signed char and that
'\377' should be reserved.  It won't work.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list