I\'d like to use a macro like the following:
#define x(...) y(a,##__VA_ARGS__,b)
To expand like so:
x(); -> y(a,b);
x(1)
That's expected behaviour. There is no standard way to swallow the comma.
Fortunately, gcc
, clang
and xlc
support the ##__VA_ARGS__
gnu extension, and msvc
swallows the comma automatically.
If you don't want to rely on above mentioned language extensions, the idiomatic ISO C90 way to get variable argument macros was like this:
#define x(args) y args
/* notice the extra parantheses */
x((a, b, c, d));
If you don't want to use either of these solutions, you can always employ argument counting, as answered here.