I'm trying to build a macro M
which will expand to one of two possibilities, depeding on whether it has one, or more than one, arguments:
M(x)
should expand to
f(x)
While
M(x, "%d%d%d", 1, 2, 3)
should expand to
g(x, "%d%d%d", 1, 2, 3)
Where the function signatures are
f(int x);
g(int x, const char *fmt, ...);
There are various answers regarding the "overloading" of macros if the argument count is known; however their methods of determining the length of __VA_ARGS__
all work only to a finite, chosen number.
Is there any trick that might make a similar approach work for my "one argument / more than 1 arguments" case?
Note:
Overloading the functions is not an option because in my case they are actually constructors for two different classes.