Does the standard require EOF to be negative?

二次信任 提交于 2019-12-12 05:14:09

问题


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 as char the type wint_t must be defined as int due to the parameter promotion.

it would be legitimate to define wchar_t as char


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!