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 chars 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 or unsigned can combined char, long, short, or int.

[dcl.type.simple] / 2

[...] table 9 summarizes valid combinations of simple-type-specifiers , types specify.

enter image description here

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -