标准是否要求EOF为负? [英] Does the standard require EOF to be negative?

查看:146
本文介绍了标准是否要求EOF为负?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否按照标准写成EOF必须为负数? 相反,WEOF不必为负.为什么? wchar_t的情况一定不能与普通char有所不同(除非从char自动升级为int起作用),因为使用charwchar_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 as char the type wint_t must be defined as int 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆