wchar_t aliasing

Discussion in 'C++' started by tni, Aug 7, 2009.

  1. tni

    tni Guest

    What are the aliasing rules for wchar_t with regards to its underlying
    int type? E.g., if wchar_t is 16-bits, is it safe to cast to uint16_t?
    tni, Aug 7, 2009
    #1
    1. Advertising

  2. tni wrote:
    > What are the aliasing rules for wchar_t with regards to its underlying
    > int type? E.g., if wchar_t is 16-bits, is it safe to cast to uint16_t?


    Section 3.9.1., paragraph 5 "Fundamental types" of the C++ standard
    tells you what you need to know. Basically, it's size and signedness are
    implementation and platform dependent.
    Robert Hairgrove, Aug 8, 2009
    #2
    1. Advertising

  3. tni

    James Kanze Guest

    On Aug 7, 11:12 am, tni <> wrote:
    > What are the aliasing rules for wchar_t with regards to its
    > underlying int type?


    That the underlying type is an integer type, whose values can
    represent distinct codes for all members of the largest extended
    character set specified among the supported locales.

    In practice, constraints of backwards compatibility mean that
    some widespread implementations aren't strictly conformant in
    regard to that last criteria---formally, it means that if any
    supported locale supports modern versions of Unicode, wchar_t
    must have at least 21 bits.

    > E.g., if wchar_t is 16-bits, is it safe to cast to uint16_t?


    The results of the cast will be well defined on all systems, but
    there's no guarantee that information won't be lost. wchar_t is
    often 32 bits (and would almost certainly be 32 bits almost
    everywhere without considerations of backwards compatibility,
    which constraint Windows and AIX to 16 bit values).

    --
    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, Aug 8, 2009
    #3
    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. Adrian Cornish
    Replies:
    2
    Views:
    8,202
    Adrian Cornish
    Jul 12, 2003
  2. Bren
    Replies:
    4
    Views:
    4,120
    Peter van Merkerk
    Oct 7, 2003
  3. sorty
    Replies:
    4
    Views:
    20,724
    Rolf Magnus
    Nov 25, 2003
  4. Jon Willeke

    wchar_t -> UTF-8?

    Jon Willeke, Feb 8, 2004, in forum: C++
    Replies:
    2
    Views:
    7,542
    Tilman Kuepper
    Feb 9, 2004
  5. Replies:
    3
    Views:
    1,099
    James Kanze
    Aug 15, 2008
Loading...

Share This Page