The C Standard defines EOF
and WEOF
with the following language:
7.21.1 Input/output<stdio.h> - Introduction
The header
<stdio.h>
defines several macros, and declares three types and many functions for performing input and output....
EOF
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 Extended multibyte and wide character utilities <wchar.h> - Introduction:
The header
<wchar.h>
defines four macros, and declares four data types, one tag, and many functions....
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
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.
- The value of the macro WEOF may differ from that of EOF and need not be negative.
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)
.
Are there any common C environments where either of these macros are defined to something different?
What is the rationale for the Standard Committee to leave open the possibility of different values and especially a non-negative value for WEOF
?