16

I've opened winnt.h header file and found there this two lines:

typedef wchar_t WCHAR;

and

typedef WCHAR TCHAR, *PTCHAR;

but there was comment in one of my posts that there is some difference between them. Then what is the difference?

Community
  • 1
  • 1
Mihran Hovsepyan
  • 10,450
  • 13
  • 59
  • 110

4 Answers4

20

If you read the entire header, you will find:

#ifdef _UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif

or words to that effect.

Perhaps MS has removed the narrow option of late.

bmargulies
  • 94,623
  • 39
  • 172
  • 299
11

TCHAR can be either char or WCHAR based on the platform. WCHAR is always a 16-bit Unicode character, wchar_t.

Wyatt Anderson
  • 9,188
  • 1
  • 20
  • 25
7

http://msdn.microsoft.com/en-us/library/aa383751%28VS.85%29.aspx

TCHAR:

A WCHAR if UNICODE is defined, a CHAR otherwise.

WCHAR:

A 16-bit Unicode character. For more information, see Character Sets Used By Fonts.

Sagar
  • 9,274
  • 6
  • 53
  • 94
0

Technically speaking there is no difference because you cannot typedef two different entities to a single one. Let us See An Example...

typedef char a;
typedef char  b;
typedef a b, c;

This Definition Works But If a Change The Above Definition To This

typedef char a;
typedef char * b;
typedef a b, c;

Error 1 error C2040: 'b' : 'a' differs in levels of indirection from 'char *'

Another One

typedef char a;
typedef int b;
typedef a b, c;

Error 1 error C2371: 'b' : redefinition; different basic types

So By Analyzing These Things Only Same Type Can Defined Together.

Mohit Dabas
  • 2,283
  • 1
  • 16
  • 12