Consider the following sample code.
#define T(q) L##q
#define A(p) T("x" T(#p))
wchar_t w[] = A(a);
Is this code well-formed? What is the value of w? Is the behavior different in C and C++? Is it different in C++0x?
I've browsed through the C++03 standard and it seems to me, that the code should be valid with w having the value L"xa".
A is found, processing thereof yields the pp sequence T ( "x" T ( "a" ) ).T is found, yielding L ## "x" T ( "a" ), which in turn yields L"x" T ( "a" ).T is found, yielding L"x" L"a".Is that correct? Neither EDG nor Clang accept the snippet, MSVC 9 compiles it just fine.
g++ expands to
L"x" T("a")
Macro cannot be recursive and they are pre-processed only in one shot, so T(#p) would not be expanded again. If you wanted L"xa" then following can be done:
#define A(p) T("x")#p
#define T(q) L##q
(It's actually L"x""a".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With