How to convert concatenated strings to wide-char with the C preprocessor?

If you want to convert a character string literal to a wide character string literal, you properly define a macro as _L here:
 
#define  _L(x)  __L(x)
#define  __L(x) L ## x
#define  STR  "I am handsome"
 
wchar_t  str1[] = _L( "I am handsome"  );
wchar_t  str2[] = _L(STR);
 
It works fine at most all compiler currently. However, when use it to convert the concatenated string like
#define STR3 "I am handsome\n" \
             "I love u\n"
 
wchar_t str3[] = _L(STR3);//error C2308: concatenating mismatched strings
 
you will get a compiler error in MSVC.
This is because it's the new feature in C99 standards. The MSVC don't support it for a long time.
If uses the GCC, the second code piece get compiled without error.
 
Look how C99 standard said.
6.4.5 String literals
In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and wide string literal tokens are concatenated into a single multibyte character sequence. If any  f the tokens are wide string literal tokens, the resulting multibyte character sequence is treated as a wide string literal; otherwise, it is treated as a character string literal.

你可能感兴趣的:(process)