Are the standards saying that casting to wint_t and to wchar_t in the following two programs is guaranteed to be correct?
#include <locale.h>
#include <wchar.h>
int main(void)
{
setlocale(LC_CTYPE, "");
wint_t wc;
wc = getwchar();
putwchar((wchar_t) wc);
}
--
#include <locale.h>
#include <wchar.h>
#include <wctype.h>
int main(void)
{
setlocale(LC_CTYPE, "");
wchar_t wc;
wc = L'ÿ';
if (iswlower((wint_t) wc)) return 0;
return 1;
}
Consider the case where wchar_t is signed short (this
hypothetical implementation is limited to the BMP), wint_t is signed int, and WEOF == ((wint_t)-1). Then (wint_t)U+FFFF is
indistinguishable from WEOF. Yes, U+FFFF is a reserved codepoint, but
it's still wrong for it to collide.
I would not want to swear that this never happens in real life without an exhaustive audit of existing implementations.
See also May wchar_t be promoted to wint_t?