是否有EOF!= -1或WEOF!= -1的任何常见C环境 [英] Are there any common C environments where EOF != -1 or WEOF != -1

查看:177
本文介绍了是否有EOF!= -1或WEOF!= -1的任何常见C环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C标准使用以下语言定义EOFWEOF:

The C Standard defines EOF and WEOF with the following language:

7.21.1输入/输出-简介

标头<stdio.h>定义了几个宏,并声明了三种类型和许多用于执行输入和输出的函数.

The header <stdio.h> defines several macros, and declares three types and many functions for performing input and output.

...

EOF

EOF

扩展为整数类型为int且为负值的整数常量表达式,该表达式由多个函数返回以指示文件结束,即不再有来自流的输入;

which expands to an integer constant expression, with type int and a negative value, that is returned by several functions to indicate end-of-file, that is, no more input from a stream;

...

7.21.1扩展的多字节和宽字符实用程序-简介:

标头<wchar.h>定义了四个宏,并声明了四种数据类型,一个标记和许多功能.

The header <wchar.h> defines four macros, and declares four data types, one tag, and many functions.

...

wint_t

wint_t

这是一个整数类型,默认情况下参数提升没有变化,可以保留与扩展字符集的成员相对应的任何值,以及至少一个与扩展字符集的任何成员不对应的值

which is an integer type unchanged by default argument promotions that can hold any value corresponding to members of the extended character set, as well as at least one value that does not correspond to any member of the extended character set

WEOF

WEOF

会扩展为类型为wint_t的常量表达式,其值不与扩展字符集的任何成员相对应.(328)此子句中的多个函数接受(并返回)该文件以指示文件结尾,也就是说,不再有来自流的输入.它也用作不与扩展字符集的任何成员相对应的宽字符值.

which expands to a constant expression of type wint_t whose value does not correspond to any member of the extended character set.(328) It is accepted (and returned) by several functions in this subclause to indicate end-of-file, that is, no more input from a stream. It is also used as a wide character value that does not correspond to any member of the extended character set.

328)宏WEOF的值可能与EOF的值不同,并且不必为负.

328) The value of the macro WEOF may differ from that of EOF and need not be negative.

EOF是负值,并且是getc()可以返回的唯一负值.我已经看到它通常定义为(-1),并且类似地将WEOF定义为((wint_t)-1).

EOF is a negative value and it is the only negative value that getc() can return. I have seen it commonly defined as (-1), and similarly WEOF defined as ((wint_t)-1).

是否存在任何将这些宏定义为不同的通用C环境?

Are there any common C environments where either of these macros are defined to something different?

标准委员会开放WEOF的不同值,尤其是非负值的可能性的理由是什么?

What is the rationale for the Standard Committee to leave open the possibility of different values and especially a non-negative value for WEOF?

推荐答案

标准委员会为WEOF留出不同价值,尤其是非负价值的可能性的理由是什么?

int类型始终是带符号的,范围中始终包含负值,因此标准可以将EOF宏定义为-1.

The type int is always signed, a negative value is always included in the range, thus the EOF macro can be defined by the standard as -1.

但是类型wint_t可以是有符号的或无符号的 1 ,因此标准不能将宏WEOF定义为特定值.实现必须选择它,由于实现定义了类型wint_t及其签名,因此还必须为WEOF选择一个值.

However the type wint_t may be signed or unsigned1, so the macro WEOF cannot be defined by the standard as a specific value. The implementation must choose it, Since the implementation defines the type wint_t and it's signedness, it must also choose a value for WEOF.

1 (引自:ISO/IEC 9899:201x 7.20.3其他整数类型5的限制)
如果将wint_t(见7.29)定义为有符号整数类型,则WINT_MIN的值应为 不大于-32767,并且WINT_MAX的值应不小于32767; 否则,将wint_t定义为无符号整数类型,并将WINT_MIN的值定义为 必须为0,且WINT_MAX的值不得小于65535.

1 (Quoted from: ISO/IEC 9899:201x 7.20.3 Limits of other integer types 5)
If wint_t (see 7.29) is defined as a signed integer type, the value of WINT_MIN shall be no greater than −32767 and the value of WINT_MAX shall be no less than 32767; otherwise, wint_t is defined as an unsigned integer type, and the value of WINT_MIN shall be 0 and the value of WINT_MAX shall be no less than 65535.

这篇关于是否有EOF!= -1或WEOF!= -1的任何常见C环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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