currently I'm trying to compile some code with Visual Studio 2015 Service Pack 2 that makes use of the following macros not written by me:
#define REM(...) __VA_ARGS__
#define EAT(...)
// Retrieve the type
#define TYPEOF(x) DETAIL_TYPEOF(DETAIL_TYPEOF_PROBE x,)
#define DETAIL_TYPEOF(...) DETAIL_TYPEOF_HEAD(__VA_ARGS__)
#define DETAIL_TYPEOF_HEAD( x , ... ) REM x
#define DETAIL_TYPEOF_PROBE(...) (__VA_ARGS__),
// Strip off the type
#define STRIP(x) EAT x
// Show the type without parenthesis
#define PAIR(x) REM x
Supposedly the TYPEOF macro would isolate the type of an expression. I have tried to invoke the TYPEOF macro with the following call:
TYPEOF( (int) m ) c;
In theory, the result should be
int c;
but instead the preprocessor outputs
int, m, c;
Replacing
#define DETAIL_TYPEOF_HEAD(x, ...) REM x
with
#define DETAIL_TYPEOF_HEAD( x , ... ) X = x and VA_ARGS = __VA_ARGS__
Yields this output:
X = (int), m, and VA_ARGS = c;
It seems that receiving the input (int), m, the DETAIL_TYPEOF_HEAD macro is unable to pick the first entry x from the variadic parameter list and instead puts the whole list into x.
Do you know this phenomenon?
Regards