Search code examples
windowsunicodetchar

Differentiate between TCHAR and _TCHAR


What are the various differences between the two symbols TCHAR and _TCHAR type defined in the Windows header tchar.h? Explain with examples. Briefly describe scenarios where you would use TCHAR as opposed to _TCHAR in your code. (10 marks)


Solution

  • Found your answer over here:

    MSDN Forums >> Visual Studio Developer Center >> TCHAR vs _TCHAR

    TCHAR and _TCHAR are identical, although since TCHAR doesn't have a leading underscore, Microsoft aren't allowed to reserved it as a keyword (imagine if you had a variable called TCHAR. Think what would happen). Hence TCHAR will not be #defined when Language Extensions are disabled (/Za).

    TCHAR is defined in winnt.h (which you'll get when you #include ), and also tchar.h under /Ze. _TCHAR is available only in tchar.h (which also #defines _TSCHAR and _TUCHAR). Those are unsigned/signed variants of the normal TCHAR data type.