That is because
wchar_t is required to hold an
WEOF value and
char is not required to hold an
putchar() functions need to accept values which can hold both values in the
unsigned char and
EOF range, where
EOF can be a negative number so a
int is required to hold them both.1
wchar_t itself is required to hold a
WEOF character as well as the biggest locale.2
WEOF represents a value which fits inside
wchar_t but doesn't overlap with any locale.3
This is made more confusing because of the the names of
wchar_t, you shouldn't see
wchar_t as a
char but more as a
int which size isn't dependent on the architecture but on the size of the biggest locale (and on the value of
2 Quoting ISO/IEC 9899:201x 7.19.2:
WEOFwhich expands to a constant expression of type
wint_twhose value does not correspond to any member of the extended character set. 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.
WEOFevaluates to a constant expression of type
wint_twhose value is different from any member of the extended character set.
wchar_tType whose range of values can represent distinct codes for all members of the largest extended character set specified among the supported locales.
wchar_tis a distinct fundamental type (and thus it is not defined in
<cwchar>nor any other header).
In c, this is a
typedefof an integral type.