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,810
  • 14
  • 61
  • 111

5 Answers5

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
  • 97,814
  • 39
  • 186
  • 310
12

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

Wyatt Anderson
  • 9,612
  • 1
  • 22
  • 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,456
  • 6
  • 54
  • 96
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,333
  • 1
  • 18
  • 12
0

TCHAR is portable type which is char for ANSI type projects and WCHAR (16-bit Unicode char) for UNICODE projects. Using TCHAR and TCHAR */LPSTR you can create portable project which can easily be recompiled for ANSI and UNICODE version. But after Windows 98/ME become obsolete and rarely used, there is no need to create non-Unicode executables.

i486
  • 6,491
  • 4
  • 24
  • 41