Mismatch in the definitions of fputwc (), putwc () and putwchar () in glibc

Why fputwc(), putwc()and putwchar()take a type argument wchar_tinstead wint_t? This contradicts the corresponding narrow functions of the symbols fputc(), putc()and putchar(), which accept int, and not char.

+2
source share
1 answer

This is because it wchar_tis required to store the value WEOF, and charnot required to store the value EOF.

For the charfunction fputc(), putc()and putchar()must take values ​​that can contain both values ​​in the range unsigned charand EOF, where EOFcan be a negative number therefore a intis required for both of them. 1

While it wchar_titself should contain a symbol WEOF, as well as the largest locale. 2WEOF represents a value that is inside wchar_tbut does not overlap with any locale. 3

This becomes more confusing due to the names charand wchar_t, you should not see wchar_thow char, but more like int, whose size does not depend on but by the size of the largest locale (and by value WEOF). 4


1 putchar, toupper, tolower .. int char?

2 ISO/IEC 9899: 201x 7.19.2:

WEOF wint_t, . ( ) , , . , .

3 :

WEOF wint_t , .

4 ++ Reference:

wchar_t, , .

, wchar_t - type (, , <cwchar> ).

c, typedef .

+3

Source: https://habr.com/ru/post/1661444/


All Articles