问题
Is it written in the standard that EOF
must be negative?
On the contrary, WEOF
is not required to be negative. Why?
The situation for wchar_t
must not be in any way different from ordinary char
(except where automatic promotion from char
to int
plays the role), because defining wchar_t
as char
is perfectly fine with the standard. Therefore, similar rules must apply.
Some quotations from glibc reference:
if
wchar_t
is defined aschar
the typewint_t
must be defined asint
due to the parameter promotion.
it would be legitimate to define
wchar_t
aschar
回答1:
Yes, it is guaranteed to be negative. See C11
7.21 Input/output
7.21.1 Introduction
1 The header defines several macros, and declares three types and many functions for performing input and output.
3 ...
EOF
which expands to an integer constant expression, with type
int
and a negative value
来源:https://stackoverflow.com/questions/40754924/does-the-standard-require-eof-to-be-negative