Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is TCHAR still relevant?

I'm new to Windows programming and after reading the Petzold book I wonder:

is it still good practice to use the TCHAR type and the _T() function to declare strings or if I should just use the wchar_t and L"" strings in new code?

I will target only Windows 2000 and up and my code will be i18n from the start up.

like image 507
Fábio Avatar asked Oct 24 '08 16:10

Fábio


People also ask

What is difference between Tchar and char?

TCHAR is simply a macro that expands to char in ANSI builds (i.e. _UNICODE is not defined) and wchar_t in Unicode builds ( _UNICODE is defined). There are various string types based on the TCHAR macro, such as LPCTSTR (long pointer to a constant TCHAR string).

What does Tchar mean?

For multibyte character set : TCHAR stands for char (simple character of 1 byte) For Unicode character set: TCHAR stands for wchar (Wide character of 2 byte) For example : If your Visual Studio project setting have character set = Multi byte character set.

What does Tchar H do?

By using the tchar. h, you can build single-byte, Multibyte Character Set (MBCS), and Unicode applications from the same sources. tchar. h defines macros (which have the prefix _tcs ) that, with the correct preprocessor definitions, map to str , _mbs , or wcs functions, as appropriate.

Where is Tchar defined?

For Unicode platforms, TCHAR is defined as synonymous with the WCHAR type. MAPI clients can use the TCHAR data type to represent a string of either the WCHAR or char type. Be sure to define the symbolic constant UNICODE and limit the platform when it is required.


1 Answers

The short answer: NO.

Like all the others already wrote, a lot of programmers still use TCHARs and the corresponding functions. In my humble opinion the whole concept was a bad idea. UTF-16 string processing is a lot different than simple ASCII/MBCS string processing. If you use the same algorithms/functions with both of them (this is what the TCHAR idea is based on!), you get very bad performance on the UTF-16 version if you are doing a little bit more than simple string concatenation (like parsing etc.). The main reason are Surrogates.

With the sole exception when you really have to compile your application for a system which doesn't support Unicode I see no reason to use this baggage from the past in a new application.

like image 67
Sascha Avatar answered Sep 22 '22 03:09

Sascha