Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > signed/unsigned wchar_t

Reply
Thread Tools

signed/unsigned wchar_t

 
 
john
Guest
Posts: n/a
 
      09-12-2007
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?
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-12-2007
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


 
Reply With Quote
 
 
 
 
john
Guest
Posts: n/a
 
      09-12-2007
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]$
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      09-13-2007
On Sep 13, 1:56 am, john <(E-Mail Removed)> wrote:
> 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:(E-Mail Removed)
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting from windows wchar_t to linux wchar_t yakir22@gmail.com C++ 3 08-15-2008 09:04 AM
wchar_t -> UTF-8? Jon Willeke C++ 2 02-09-2004 08:05 AM
std::wstring, TCHAR, wchar_t and LPTSTR sorty C++ 4 11-25-2003 11:05 AM
string class that can convert between wchar_t and char Bren C++ 4 10-07-2003 03:24 PM
wchar_t wstring char string transformations Adrian Cornish C++ 2 07-12-2003 08:05 PM



Advertisments