Suppose I have a C++ preprocessor macro defined as follows:
#define X(s) std::cout << #s
if I use it directly:
int main() {
X( hello );
}
It works as expected and "hello" is printed on the console.
If I define another macro that calls it:
#define Y X( hello )
#define X(s) std::cout << #s
int main() {
Y;
}
It still works.
However if I try to compose the call to X from two or more different macros, I get a whole bunch of errors:
#define A X(
#define B hello
#define C )
#define X(s) std::cout << #s << '\n'
int main()
{
A B C;
}
See output at: http://cpp.sh/5ws5k
Why can't I compose a macro call from two or more macro expansions, doesn't preprocessor expand them recursively?