Differentiate between TCHAR and _TCHAR
Asked Answered
R

2

8

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)

Randee answered 1/6, 2010 at 10:25 Comment(3)
why does your question sound like a homework ? can't you take the time to rephrase your exam and make it sound more personnal ?Alyciaalyda
I actually took extra time and went out of my way to make it sound like homework. Tiring to see all these little idiosyncrasies in Windows headers with no rhyme or reason.Randee
tchar.h is not part of the Windows SDK, but is part Microsoft CRT...Alyciaalyda
M
8

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.

Motmot answered 1/6, 2010 at 10:31 Comment(0)
G
10

In addition to what @RussC said, TCHAR is used by the Win32 API and is based on the UNICODE define, whereas _TCHAR is used by the C runtime and is based on the _UNICODE define instead. UNICODE and _UNICODE are usually defined/omitted together, making TCHAR and _TCHAR interchangable, but that is not a requirement. They are semantically separated for use by different frameworks.

Gynoecium answered 13/7, 2012 at 2:37 Comment(0)
M
8

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.

Motmot answered 1/6, 2010 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.