c++ - Why is char neither signed or unsigned, but wchar_t is? -
the following c++ program compiles without errors:
void f(char){} void f(signed char){} void f(unsigned char){} int main(){}
the wchar_t
version of same program not:
void f(wchar_t){} void f(signed wchar_t){} void f(unsigned wchar_t){} int main(){}
error: redefinition of ‘void f(wchar_t)’
void f(signed wchar_t){}
it seems wchar_t
unsigned
.
why there inconsistency in overloading?
the char
s distinct types , can overloaded
[basic.fundamental] / 1
[...] plain
char
,signed char
, ,unsigned char
3 distinct types, collectively called narrow character types. [...]
wchar_t
distinct type, cannot qualified signed
or unsigned
, can used standard integer types.
[dcl.type] / 2
as general rule, @ 1 type-specifier allowed in complete decl-specifier-seq of declaration or in type-specifier-seq or trailing-type-specifier-seq. exceptions rule following:
[...]
signed
orunsigned
can combinedchar
,long
,short
, orint
.
[dcl.type.simple] / 2
[...] table 9 summarizes valid combinations of simple-type-specifiers , types specify.
the signedness of wchar_t
implementation defined:
[basic.fundamental] / 5
[...] type
wchar_t
shall have same size, signedness, , alignment requirements (3.11) 1 of other integral types, called underlying type.
Comments
Post a Comment