gcc does support argument counting macros with zero arguments with the ## __VA_ARGS__
convention. The following works compiled with gcc:
#include <stdio.h>
#define NARGS(...) __NARGS(0, ## __VA_ARGS__, 5,4,3,2,1,0)
#define __NARGS(_0,_1,_2,_3,_4,_5,N,...) N
int main()
{
printf("%d\n", NARGS()); // prints 0
printf("%d\n", NARGS(1)); // prints 1
printf("%d\n", NARGS(1, 2)); // prints 2
return 0;
}
Is there an equivalent for VisualC++ that will work with zero arguments macros? Non standard extensions or tricks accepted.
EDIT: Fixed the example to work with GCC extensions and C++ compiler.