wchar_t vs. char16_t

Discussion in 'C++' started by A, Sep 20, 2011.

  1. A

    A Guest

    whats the difference?
     
    A, Sep 20, 2011
    #1
    1. Advertising

  2. A

    Rui Maciel Guest

    A wrote:

    > whats the difference?


    Both are different integral types defined in the standard, the latter added
    in C++x11. While wchar_t is intended to store information in a format that
    depends on the locale, char16_t appears to have been defined with the
    specific purpose of encoding information following the UTF-16 format (as
    char32_t with the UTF-32 format).

    So, in practical terms, the main difference is that by using char16_t and
    char32_t you specifically know what format is being used to encode your text
    strings, while with wchar_t you don't.


    Rui Maciel
     
    Rui Maciel, Sep 20, 2011
    #2
    1. Advertising

  3. On Sep 20, 12:39 pm, Rui Maciel <> wrote:
    > A wrote:
    > > whats the difference?


    wchar_t has implementation defined size. On most unix-like systems,
    it's 32 bit. On windows, it's 16 bit. If you're trying to use C++
    locales portably, then it might make sense to use wchar_t. However,
    the C++ locales are largely non-portable, which makes use of wchar_t
    largely non-portable.

    > Both are different integral types defined in the standard, the latter added
    > in C++x11.  While wchar_t is intended to store information in a format that
    > depends on the locale, char16_t appears to have been defined with the
    > specific purpose of encoding information following the UTF-16 format (as
    > char32_t with the UTF-32 format).  
    >
    > So, in practical terms, the main difference is that by using char16_t and
    > char32_t you specifically know what format is being used to encode your text
    > strings, while with wchar_t you don't.


    To be technical, you can put whatever kind of data you want into
    char16_t. It does lend itself to storing UTF16, but it doesn't require
    that you put UTF16 into char16_t.
     
    Joshua Maurice, Sep 20, 2011
    #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,210
    Adrian Cornish
    Jul 12, 2003
  2. Bren
    Replies:
    4
    Views:
    4,125
    Peter van Merkerk
    Oct 7, 2003
  3. sorty
    Replies:
    4
    Views:
    20,737
    Rolf Magnus
    Nov 25, 2003
  4. Jon Willeke

    wchar_t -> UTF-8?

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

Share This Page