Macro string: what does #define __T (x) x mean? And __T (#x)?

What does it mean?

#define __T(x)  x

Just return x?

I see code using syntax that I have not seen before:

#define CREATE_ENCODER(CODEC) \
strcpy(codecName, __T(#CODEC); \
pCodec = new CODEC##VideoEncoder();
if(parFileName) \
{  pEncoderParams = new CODEC##EncoderParams; \
}

What is # for?

+3
source share
2 answers

Yes, this parameter is simply replaced by the passed value. This type of definition is often used if, for example, you want to determine at compile time, if you want to pass a value through a translation function ( #define __T(x) translate(x)) or not ( #define __T(x) x).

#builds the passed value: http://gcc.gnu.org/onlinedocs/cpp/Stringification.html and
##- the concatenation operator: http://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

+10
source

__T wchar_t * char *, tchar.h :

#define __T(x)      L ## x

, UNICODE

#define __T(x)      x

UNICODE, UNICODE, :

TCHAR * sz = __T (" ");

WINAPI TCHAR *

_T(), , __T, tchar.h :

#define _T(x)       __T(x)
#define _TEXT(x)    __T(x)

, :

strcpy(codecName, __T(#CODEC)); \

:

strcpy(codecName, "CODEC"); \

,

strcpy(codecName, L"CODEC"); \

UNICODE

!!: _T __T , , UNICODE. WINAPI. UNICODE.

+8

All Articles