C Language Preprocessor and Macros Token pasting


Example

Token pasting allows one to glue together two macro arguments. For example, front##back yields frontback. A famous example is Win32's <TCHAR.H> header. In standard C, one can write L"string" to declare a wide character string. However, Windows API allows one to convert between wide character strings and narrow character strings simply by #defineing UNICODE. In order to implement the string literals, TCHAR.H uses this

#ifdef UNICODE
#define TEXT(x) L##x
#endif

Whenever a user writes TEXT("hello, world"), and UNICODE is defined, the C preprocessor concatenates L and the macro argument. L concatenated with "hello, world" gives L"hello, world".