The ISO C90 standard, where wchar_t was introduced, does not say anything specific about the representation. It only requires that this type is capable of storing all elements of the basic character set.
Which means that wchar_t
may well be of type char
, and wint_t
may be
of type int
. Further, in some implementations wchar_t
may be signed,
and in some - unsigned. How is the situation different from putchar()
?
For comparison, the argument of putchar()
, putc()
and fputc()
was chosen to be int
.
I think that none of the library functions which handle single
characters work with char
(only with int
), because even though
some of them do not use EOF (like putchar()
), we cannot make its type char
,
because if it was char
, and we typecast to unsigned char
(the signedness of char
is not standardized), there would be type
conversion warnings like
void f(char c) { ...
...
int x = 't';
f((unsigned char)x);
...
warning: conversion to ‘char’ from ‘unsigned char’ may change the sign of the result
So the only option was to make it int
, which can hold both signed and unsigned char
.
Although the argument is automatically converted to unsigned char
by putchar() even if
it was passed as int or signed char, nothing of the sort is done in putwchar().
So, why fputwc()
, putwc()
and putwchar()
take wchar_t
, not wint_t
? Seems like a flaw in the standard. Am I missing something obvious?
See also Why islower() and friends are required to handle EOF? and Why argument type of putchar()
, fputc()
and putc()
is not char
? and Inconsistency in definitions of fputwc(), putwc() and putwchar() in glibc
UPDATE
some quotations from glibc reference
if
wchar_t
is defined aschar
the typewint_t
must be defined asint
due to the parameter promotion.
it would be legitimate to define
wchar_t
aschar
Is fact, these functions had correct interfaces in "ISO Working Paper SC22/WG14/N204 dated 31st March 1992" (which is the final draft before publishing "ISO/IEC 9899:1990/Amendment 1:1995"), but they were changed in "ISO/IEC 9899:1990/Amendment 1:1995". See here http://www.unix.org/version2/whatsnew/login_mse.html