WEOF in integer constant expressionsAuthors: Jay Ghiron
Date: 2026-05-08
Submitted against: C23
Status: Open
Unlike most macros in the standard library, WEOF is described as
expanding to a constant expression of a particular type without
defining it as an integer constant expression:
The macros defined are
NULL(described in 7.21);WCHAR_MIN,WCHAR_MAX, andWCHAR_WIDTH(described in 7.22); and
WEOFwhich expands to a constant expression of type
wint_twhose value does not correspond to any member of the extended character set.
(C23 7.31.1 "Introduction" paragraph 4.)
Since it is not described as an integer constant expression, the following definition is currently permitted:
#define WEOF ((__wint_t)-1.)
/* __wint_t instead of wint_t to avoid issues with local definitions
of wint_t */
Which is neither an integer constant expression nor usable in conditional expression inclusion preprocessing directives. Therefore the following uses might be invalid:
#if WEOF<0
/*...*/
#endif
enum{NegativeWEOF=WEOF<0};
It seems unintended to allow definitions that preclude these uses.
Note that MSVC cannot make the former case work because it defines
wint_t as unsigned short, though that is not a valid definition of
wint_t.
Modify C23 7.31.1 paragraph 4:
The macros defined are
NULL(described in 7.21);WCHAR_MIN,WCHAR_MAX, andWCHAR_WIDTH(described in 7.22); and
WEOFwhich expands to an integer constant expression of type
wint_twhose value does not correspond to any member of the extended character set.