K
KOFKS
I have come across a problem when I'm reading "comp.lang.c FAQ list ·
Question 12.1".
This item is about
char c;
while((c = getchar()) != EOF) ...
One paragraph of the item writes:"If type char is unsigned, an actual
EOF value will be truncated (by having its higher-order bits discarded,
probably resulting in 255 or 0xff) and will not be recognized as EOF,
resulting in effectively infinite input. "
However, in the C99 standard 6.5.9 Equality operators Semantics, I see
the following:
"...Any two values of arithmetic types from different type domains are
equal if and only if the results of their conversions to the (complex)
result type detemined by the usual arithmetic conversions are equal."
As I know, the usual arithmetic conversion of char is that it will be
converted to int during the integral promotion process. Why does EOF be
truncated other than the char variable be promoted by zero extension at
the case mentioned above?
So there must be something wrong. Am I misunderstanding something?
Can anyone help?
TIA.
Question 12.1".
This item is about
char c;
while((c = getchar()) != EOF) ...
One paragraph of the item writes:"If type char is unsigned, an actual
EOF value will be truncated (by having its higher-order bits discarded,
probably resulting in 255 or 0xff) and will not be recognized as EOF,
resulting in effectively infinite input. "
However, in the C99 standard 6.5.9 Equality operators Semantics, I see
the following:
"...Any two values of arithmetic types from different type domains are
equal if and only if the results of their conversions to the (complex)
result type detemined by the usual arithmetic conversions are equal."
As I know, the usual arithmetic conversion of char is that it will be
converted to int during the integral promotion process. Why does EOF be
truncated other than the char variable be promoted by zero extension at
the case mentioned above?
So there must be something wrong. Am I misunderstanding something?
Can anyone help?
TIA.