By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,307 Members | 1,950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,307 IT Pros & Developers. It's quick & easy.

signed/unsigned wchar_t

P: n/a
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?
Sep 12 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
john wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 12 '07 #2

P: n/a
Victor Bazarov wrote:
john wrote:
>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

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]$
Sep 13 '07 #3

P: n/a
On Sep 13, 1:56 am, john <j...@no.spamwrote:
Victor Bazarov wrote:
john wrote:
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.
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.
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?
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 13 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.