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?
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).