what is wchar_t

S

sarathy

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

Regards,
Sarathy
 
C

Clever Monkey

sarathy said:
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.
 
O

Old Wolf

sarathy said:
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.
 
K

Keith Thompson

Old Wolf said:
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.
 
G

Guest

Keith said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

wchar_t is useless 18
Using wchar_t instead of char 15
3 questions on wchar_t 2
wchar_t aliasing 2
c16rtomb example wrong? 0
char & wchar_t 5
C can be very literal. 22
wchar_t 39

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top