I know that the _T(x) macro converts a string literal to a unicode/multibyte string based on a define, however I find it very annoying that I must make a underscore and the parenthesis, it really confuses me, I'm not quiet fluent with macros so I don't know, is there a way to detect all string literals and convert them to a proper unicode/multibyte string?
-
Unicode? Multi-byte? Drop C and go Python :) – salezica Mar 22 '14 at 10:13
-
Just don't bother, [a char literal is an *int*](http://stackoverflow.com/questions/433895/why-are-c-character-literals-ints-instead-of-chars). So it just doesn't matter. – Hans Passant Mar 22 '14 at 10:29
-
Use `L` for your literals since I cannot believe you are building for Win98 – David Heffernan Mar 22 '14 at 14:27
3 Answers
No, there isn't a way to avoid the macro completely if you want your code to be portable on Windows. You can of course define your own macro like #define t(x) whatever_T_does
if you want to save yourself some keystrokes, but this will probably anger future maintainers of your code.

- 239,568
- 38
- 324
- 436
_T()
and _TEXT()
are C runtime macros, not Win32 macros. TEXT()
(no underscore) is the Win32 macro. Even though they essentially do the same thing, you should use C runtime macros only with C functions, and Win32 macros with Win32 functions. Don't mix them.

- 555,201
- 31
- 458
- 770
Do you really need the ability to compile for both multibyte and Unicode? You don't need any macro if you want multibyte. In a Unicode app it is easier to use L"literal string", which does not need the underscore or the parentheses.

- 10,337
- 2
- 15
- 15