Actual implementation of EOF different from -1

只愿长相守 提交于 2019-12-01 02:04:29

问题


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

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

EOF

End-of-file return value.

In every implementation I could find, EOF is always defined as -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

1I could make my own implementation, but my real purpose is to "find it in the wild", which, due to the impossibility of proving its absence, is the next best thing I can think of.

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.

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.


回答1:


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)    */

:-)

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. :-(



来源:https://stackoverflow.com/questions/48583103/actual-implementation-of-eof-different-from-1

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