getchar and EOF (was: One more point regarding = and == (more flamage))

Blair P. Houghton bhoughto at nevin.intel.com
Tue Apr 9 16:32:39 AEST 1991


In article <1991Apr7.064003.8552 at athena.mit.edu> scs at adam.mit.edu writes:
>I was going to say that "EOF is guaranteed not to compare equal
>to any char value," but this is not really true.  If you have
>
>	signed char c = '\377';
>
>and EOF is -1, then c == EOF will succeed.  ("signed" is a new
>ANSI C keyword; the test also succeeds if c is a "plain" char, on
>machines for which plain chars are signed.)

This is a strong example of the oft-forgotten distinction that
`char' is a datatype that implies bytes rather than characters.

If one could assume only characters, then (barring
locale-specific features) one can assume (7-bit) ascii,
which has values only from '\0' to '\177', obviating this
confusion with `(signed char)(-1)'.  But one can't, so one
shouldn't (the ascii-only assumption is bogus at the
outset, since it ignores the loadable (8-bit) fonts of most
ANSI terminals, of which DEC VT character terminals are a
near conformant).

But like I said before, anything much more complex than
7-bit ascii usually deserves more care than getchar(3).

				--Blair
				  "Trigraphs? We don' got no trigraphs...
				   We don' need no steenking trigraphs!"



More information about the Comp.lang.c mailing list