signed/unsigned wchar_t

Discussion in 'C++' started by john, Sep 12, 2007.

  1. john

    john Guest

    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?
     
    john, Sep 12, 2007
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Sep 12, 2007
    #2
    1. Advertising

  3. john

    john Guest

    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]$
     
    john, Sep 13, 2007
    #3
  4. john

    James Kanze Guest

    On Sep 13, 1:56 am, john <> 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:
    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
     
    James Kanze, Sep 13, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier Roche

    Re: wchar_t: signed or unsigned?

    Xavier Roche, Apr 21, 2014, in forum: C Programming
    Replies:
    0
    Views:
    85
    Xavier Roche
    Apr 21, 2014
  2. Seungbeom Kim

    Re: wchar_t: signed or unsigned?

    Seungbeom Kim, Apr 21, 2014, in forum: C Programming
    Replies:
    3
    Views:
    80
    James Kuyper
    Apr 21, 2014
  3. James Kuyper

    Re: wchar_t: signed or unsigned?

    James Kuyper, Apr 21, 2014, in forum: C Programming
    Replies:
    0
    Views:
    82
    James Kuyper
    Apr 21, 2014
  4. Stephen Sprunk

    Re: wchar_t: signed or unsigned?

    Stephen Sprunk, Apr 21, 2014, in forum: C Programming
    Replies:
    2
    Views:
    96
    Keith Thompson
    Apr 21, 2014
  5. Malcolm McLean

    Re: wchar_t: signed or unsigned?

    Malcolm McLean, Apr 22, 2014, in forum: C Programming
    Replies:
    2
    Views:
    78
    Keith Thompson
    Apr 22, 2014
Loading...

Share This Page