Igor Liferenko Igor Liferenko - 16 days ago 6
C Question

Why argument type of `putchar()`, `fputc()` and `putc()` is not `char`?

Does anybody know Why argument type of

putchar()
,
fputc()
and
putc()
is not
char
, but argument type of
putwchar()
,
fputwc()
and
putwc()
is
wchar_t
? See also this and this.

Answer

The answer is 'legacy' (or 'history'). Before the C90 standard, there were no function prototypes and all arguments to all functions were subject to default promotion rules, so a char was automatically passed as an int (short was promoted to int too, and float to double, and similarly for unsigned types). The standard couldn't afford to break existing code, so it kept that type for these functions. It makes very little difference in practice. The value you pass will be treated as a char even if you pass a value that's out of range.