Long story short, gcc and vc++ preprocessors have different output with the same input. It seems like variadic macros in vc++ doesn't do 'argument matching' (if its the right term) if passed to another macros. For example:
#define MACRO(a, ...) head:a, tail:MACRO_OTHER(__VA_ARGS__)
#define MACRO_OTHER(a, ...) head:a, tail:__VA_ARGS__
With
MACRO(1, 2, 3, 4, 5)
gcc output:
head:1, tail:head:2, tail:3,4,5
vc++ output:
head:1, tail:head:2,3,4,5, tail:
Apparently a
in MACRO_OTHER
is 2,3,4,5
with empty variadic arguments section.
With this in mind, is there any way to create a vc++ alternative to the following macro (which works great with gcc)
#define VA_TYPES_WITH_ARGS(...) __VA_TYPES_WITH_ARGS(VA_NUM_ARGS(__VA_ARGS__),##__VA_ARGS__)
#define __VA_TYPES_WITH_ARGS(n, ...) _VA_TYPES_WITH_ARGS(n,##__VA_ARGS__)
#define _VA_TYPES_WITH_ARGS(n, ...) _VA_TYPES_WITH_ARGS_##n(__VA_ARGS__)
#define _VA_TYPES_WITH_ARGS_0()
#define _VA_TYPES_WITH_ARGS_1(type ) type _arg1
#define _VA_TYPES_WITH_ARGS_2(type, ...) type _arg2, _VA_TYPES_WITH_ARGS_1(__VA_ARGS__)
#define _VA_TYPES_WITH_ARGS_3(type, ...) type _arg3, _VA_TYPES_WITH_ARGS_2(__VA_ARGS__)
// etc
It basically appends _argK
for each argument.
Example:
VA_TYPES_WITH_ARGS(int, bool, float)
will expand to
int _arg3, bool _arg2, float _arg1
Any help will be greatly appreciated.
Related preprocessor questions:
BOOST_PP_ENUM
macro if I'm not mistaken. – chris::
, isn't it? – chris