标准是否要求EOF为负? [英] Does the standard require EOF to be negative?
问题描述
是否按照标准写成EOF
必须为负数?
相反,WEOF
不必为负.为什么?
wchar_t
的情况一定不能与普通char
有所不同(除非从char
自动升级为int
起作用),因为使用char
将wchar_t
定义为char
是完全可以的.标准.因此,必须应用类似的规则.
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.
glibc参考中的一些引用:
Some quotations from glibc reference:
如果将
wchar_t
定义为char
,则由于参数升级,必须将类型wint_t
定义为int
.
if
wchar_t
is defined aschar
the typewint_t
must be defined asint
due to the parameter promotion.
将
wchar_t
定义为char
推荐答案
是的,它肯定是负数.参见C11
Yes, it is guaranteed to be negative. See C11
7.21输入/输出
7.21.1简介
1标头定义了几个宏,并声明了三种类型和许多类型 用于执行输入和输出的功能.
1 The header defines several macros, and declares three types and many functions for performing input and output.
3 ...
EOF
扩展为类型为int
且为负值的整数常量表达式
which expands to an integer constant expression, with type int
and a negative value
这篇关于标准是否要求EOF为负?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!