Consider this C++ program:
#include <cstdio>
#define FOO BAR
#define BAR FOO
#define QUOTE(X) #X
#define EXPAND(X) QUOTE(X)
int main()
{
printf("%s expands to %s\n", QUOTE(FOO), EXPAND(FOO));
printf("%s expands to %s\n", QUOTE(BAR), EXPAND(BAR));
}
It outputs:
FOO expands to FOO
BAR expands to BAR
This is because FOO expands to BAR which expands to FOO which is not expanded again. And similarly for the second line.
Question: Is it possible to swap FOO and BAR with macros? I.e., is it possible to replace the two lines:
#define FOO BAR
#define BAR FOO
with something else so that the program will output:
FOO expands to BAR
BAR expands to FOO