Eric said:
All characters in the "basic execution character set,"
including '\n', must have non-negative values. EOF must
have a negative value.
Thanks for the pointer.
That EOF had to be negative was obvious; that '\n' had to be nonnegative
was not, hence the question. The standard does in fact say this,
indirectly, as I wager it says most things indirectly. (Give me a break,
I've never read it before.
You need to puzzle it together from the following sections:
5.2.1.3. "[..] In the basic execution character set, there shall be
control characters representing alert, backspace, carriage return, and
new line."
This establishes that newline (or very precisely, a control character
representing newline) is part of the basic execution charset.
5.2.2.2. "Alphabetic escape sequences representing nongraphic characters
in the execution character set are intended to produce actions on
display devices as follows: [..] \n (new line) Moves the active position
to the initial position of the next line."
This (indirectly) establishes that '\n' is in fact the escape sequence
for newline. (Trivial but necessary.)
6.2.5.3. "An object declared as type char is large enough to store any
member of the basic execution character set. If a member of the basic
execution character set is stored in a char object, its value is
guaranteed to be nonnegative. [...]"
The main attraction, but it only applies to characters stored in char
objects and '\n' is just a constant, so we're *not* done yet.
6.4.4.4.10. "[..] If an integer character constant contains a single
character or escape sequence, its value is the one that results when an
object with type char whose value is that of the single character or
escape sequence is converted to type int."
Now,
- by 5.2.1.3., the control character representing newline is a member of
the basic execution character set;
- by 6.4.4.4.10., the value of the constant '\n' is the value that
results when an object of type char whose value is that of '\n' is
converted to type int;
- by 5.2.2.2., '\n' is the escape sequence for the control character
representing newline;
- by 6.2.5.3. and the above, the value of '\n' is guaranteed to be
nonnegative.
QED. I'm starting to see why reading the standard isn't everyone's
favorite pastime.
S.