Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between 'WCHAR' and 'wchar_t'?

Tags:

Is there any practical difference between WCHAR and wchar_t?

like image 965
stimms Avatar asked Feb 18 '09 16:02

stimms


People also ask

What's the difference between Wchar and char?

The type unsigned char is often used to represent a byte, which isn't a built-in type in C++. The wchar_t type is an implementation-defined wide character type.

Why do we use wchar_t in C++?

wchar_t is used when you need to store a character over ASCII 255 , because these characters have a greater size than our character type 'char'. Hence, requiring more memory. It generally has a size greater than 8-bit character. The windows operating system uses it substantially.

Is wchar_t signed?

wchar_t is unsigned. Corresponding assembly code says movzwl _BOM, %eax .

What is Olechar?

OLECHAR is the character type specifically used by COM (Component Object Model), a MSFT technology for creating platform independent objects (analogous to a C++ object but not tied to C++, though C++ is often used to create them - COM objects can be accessed by anyone who follows the COM protocol in any language or on ...


2 Answers

wchar_t is a distinct type, defined by the C++ standard.

WCHAR is nonstandard, and as far as I know, exists only on Windows. However, it is simply a typedef (or possibly a macro) for wchar_t, so it makes no practical difference.

Older versions of MSVC did not have wchar_t as a first-class type—instead it was simply a typedef for short

Most likely, Microsoft introduced WCHAR to represent a "wide character type" across any compiler version, whether or not wchar_t existed as a native type.

You should use wchar_t in your code though. That's what it's for.

like image 68
jalf Avatar answered Oct 21 '22 09:10

jalf


Well, one practical difference would be that WCHAR doesn't exist on my platform. For Windows only (and with no intention of ever porting the program to another platform) and with the necessary headers included, it's the same (since WCHAR is just a typedef).

like image 22
Konrad Rudolph Avatar answered Oct 21 '22 09:10

Konrad Rudolph