signed/unsigned wchar_t

J

john

As far as I know there is only the type wchar_t. However my compiler
compiles both "signed wchar_t" and "unsigned wchar_t".

Are there both signed and unsigned wchar_t types?
 
V

Victor Bazarov

john said:
As far as I know there is only the type wchar_t. However my compiler
compiles both "signed wchar_t" and "unsigned wchar_t".

Are there both signed and unsigned wchar_t types?

It is unspecified (or, probably, implementation-defined, but I did
not find the exact place) whether 'wchar_t' is signed or unsigned,
and what would happen if you apply 'signed' to it. What I've found
is that 'wchar_t' has an *underlying* integral type, and that the
specifier "signed" is superfluous with integral types. Whether it
is legal to specify 'wchar_t' as "unsigned" I am not sure.

V
 
J

john

Victor said:
It is unspecified (or, probably, implementation-defined, but I did
not find the exact place) whether 'wchar_t' is signed or unsigned,
and what would happen if you apply 'signed' to it. What I've found
is that 'wchar_t' has an *underlying* integral type, and that the
specifier "signed" is superfluous with integral types. Whether it
is legal to specify 'wchar_t' as "unsigned" I am not sure.

V


The code

int main()
{
signed wchar_t c;
}

produces in my compiler:


[john@localhost extract]$ g++ temp.cpp -o temp

[john@localhost extract]$ g++ -ansi temp.cpp -o temp

[john@localhost extract]$ g++ -ansi -pedantic-errors temp.cpp -o temp
temp.cpp: In function ‘int main()’:
temp.cpp:3: error: long, short, signed or unsigned used invalidly for ‘c’

[john@localhost extract]$
 
J

James Kanze

It's illegal, although it is interesting that the standard feels
it necessary to say explicitly that "there are no signed,
unsigned, short, or long bool types or values" but doesn't feel
the need to be this explicit about wchar_t.
int main()
{
signed wchar_t c;
}
produces in my compiler:
[john@localhost extract]$ g++ temp.cpp -o temp
[john@localhost extract]$ g++ -ansi temp.cpp -o temp
[john@localhost extract]$ g++ -ansi -pedantic-errors temp.cpp -o temp
temp.cpp: In function ?int main()?:
temp.cpp:3: error: long, short, signed or unsigned used invalidly for ?c?

Which rather answers the question, doesn't it? If something
compiles with plain g++, and not with g++ -std=c++98 -pedantic,
then it's obviously a g++ extension.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top