Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 views
in Technique[技术] by (71.8m points)

c - Actual implementation of EOF different from -1

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

1 I 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...