what is wchar_t

Discussion in 'C Programming' started by sarathy, Jul 28, 2006.

  1. sarathy

    sarathy Guest

    Hi ,
    Can anyone please explain what are wide characters (wchar_t).
    Why is it used when there is char datatype ?

    Regards,
    Sarathy
    sarathy, Jul 28, 2006
    #1
    1. Advertising

  2. sarathy wrote:
    > Hi ,
    > Can anyone please explain what are wide characters (wchar_t).
    > Why is it used when there is char datatype ?
    >

    It's the 'w'ide 'char'acter 't'ype. A constant example would be L'X'.

    See wchar.h, added with Amendment 1.
    Clever Monkey, Jul 28, 2006
    #2
    1. Advertising

  3. sarathy

    Old Wolf Guest

    sarathy wrote:
    > Hi ,
    > Can anyone please explain what are wide characters (wchar_t).


    Characters with more than 256 possible values

    > Why is it used when there is char datatype ?


    char is limited to 256 possible values, on most computers.
    In order to write text in other languages, you need many
    more possible characters.
    Old Wolf, Jul 29, 2006
    #3
  4. "Old Wolf" <> writes:
    > sarathy wrote:
    >> Can anyone please explain what are wide characters (wchar_t).

    >
    > Characters with more than 256 possible values


    Well, char can have more than 256 possible values if CHAR_BIT > 8.

    For that matter, I don't think there's any guarantee that wchar_t
    actually can represent more than 256 values, though it's fairly
    pointless if it can't.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Jul 29, 2006
    #4
  5. Keith Thompson wrote:
    > "Old Wolf" <> writes:
    > > sarathy wrote:
    > >> Can anyone please explain what are wide characters (wchar_t).

    > >
    > > Characters with more than 256 possible values

    >
    > Well, char can have more than 256 possible values if CHAR_BIT > 8.
    >
    > For that matter, I don't think there's any guarantee that wchar_t
    > actually can represent more than 256 values, though it's fairly
    > pointless if it can't.


    There's not any guarantee that wchar_t can represent more than 255
    values, if it is signed. I wouldn't call it pointless though: code
    shouldn't have to check whether wchar_t is defined, and use char if it
    isn't. You can simply assume wchar_t exists, and if the implementation
    does not support multibyte characters, the code will still work as well
    as possible. Pretty much every important string function has both a
    narrow and a wide string version, and every one would have to be
    wrapped in a #if USE_WCHAR_T block otherwise.
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Jul 29, 2006
    #5
    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,183
    Adrian Cornish
    Jul 12, 2003
  2. Bren
    Replies:
    4
    Views:
    4,113
    Peter van Merkerk
    Oct 7, 2003
  3. sorty
    Replies:
    4
    Views:
    20,703
    Rolf Magnus
    Nov 25, 2003
  4. Jon Willeke

    wchar_t -> UTF-8?

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

Share This Page