On Visual Studio 2005 I have a macro that looks like this (examplified!!):
#define MY_CALL(FUN, ...) \
if(prepare(x, y)) { \
FUN(__VA_ARGS__); \
}
/**/
As long as the function takes at least one argument, I'm fine.
When the function takes zero arguments, the preprocessor "helpfully" removes the "trailing comma", expanding something like this:
if(prepare(x y)) { funct(); }
Great, isn't it?
How can I fix this macro, so that it'll work with zero __VA_ARGS__
on Visual C++ (VS 2005)?
Apparently this is a bug in VS2005.
Unfortunately, I do not use Visual C++ anymore (and as so cannot verify this works), but can you try this?
#define MY_CALL(FUN, ...) \
if(prepare(x, y)) { \
int fail[] = {0,} \
FUN(__VA_ARGS__); \
}
Using gcc 4.2, both {0,}
and {0}
are allowed in that context, so if the comma gets deleted or not it would not matter. However, I am not certain whether that is generally accepted in the spec, a commonly implemented extension, or something specific to gcc.
If the {0,}
syntax is allowed by Visual C++, then this would hopefully solve your problem (assuming I understand correctly that the most recent comma before __VA_ARGS__
is what is being incorrectly deleted, regardless of where it is appearing in the syntax).
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