EOF的实际实现不同于-1 [英] Actual implementation of EOF different from -1

查看:96
本文介绍了EOF的实际实现不同于-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

POSIX EOF定义为宏扩展变为负值:

POSIX defines EOF as a macro expanding to a negative value:

标头应定义以下宏,该宏将扩展为类型为 int 且为负值的整数常量表达式:

The header shall define the following macro which shall expand to an integer constant expression with type int and a negative value:

EOF

文件结束返回值.

每个实现中,我发现EOF总是定义为-1.

In every implementation I could find, EOF is always defined as -1.

尽管该标准允许使用不同的值,但我找不到发生这种情况的任何特定实现,因此我想为测试目的找到一个实现. 1

Although the standard does allow for different values, I could not find any specific implementation where that happens, and I'd like to find one for testing purposes.1

1 我可以自己实现,但我的真正目的是在野外找到它",由于无法证明它的缺席,因此是次佳的选择我能想到的事情.

已经提出了几乎相同的问题,但是最后提出了两个问题,被接受的答案仅是答案第二个(大约WEOF).另一个用户回答否定中的第一个问题,但是由于该问题仅限于常见的C环境,否定性可以说是正确的: -1可能会用于任何明智的实现中具有小字符类型.

An almost identical question has already been asked, however there were two questions asked at the end, and the accepted answer only answers the second one (about WEOF). A different user replied to the first question in the negative, but because the question was restricted to common C environments, the negative is arguable correct: -1 is likely to be used in any sensible implementation with small char type.

由于我的问题是关于 existence 的,所以真正回答它的唯一方法是提供一个示例,所以我将其重新表述:请提供一个现有实现的示例,其中 .无论是newlib还是musl,PDP或VAX,Plan 9或Hurd,libc/硬件/操作系统与POSIX兼容或ISO C兼容的libc的任意组合都是有效的.

Since my question is about existence, the only way to actually answer it is to provide an example, so I will rephrase it: please provide an example of an existing implementation where EOF != -1. Be it newlib or musl, PDP or VAX, Plan 9 or Hurd, any combination of libc/hardware/operating system with a POSIX-compatible or ISO C-compatible libc where this happens is valid.

推荐答案

懒惰的星期日,所以我发现了这个 rel ="nofollow noreferrer"> https://github.com/xinu-os/xinu/blob/master/include/stddef.h 列出

Lazy Sunday, so I found this https://github.com/xinu-os/xinu which comes with this https://github.com/xinu-os/xinu/blob/master/include/stddef.h listing this

#define EOF (-2) /**< End-of-file (usually from read)    */

:-)

可追溯到1987年的Xinu来源在这里: https://www.tuhs.org//cgi-bin/utree.pl?file=Xinu7 ,不幸的是,它似乎将-1用作EOF的值. :-(

Xinu sources dated back to 1987 are here: https://www.tuhs.org//cgi-bin/utree.pl?file=Xinu7 which unfortunately seem to be using -1 as value for EOF. :-(

这篇关于EOF的实际实现不同于-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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