For example I want to write my own printf() alternative, but I have to perform calculations on the variable arguments:
#define log(fmt_string, ...) my_log(fmt_string, pack_args(__VA_ARGS__), __VA_ARGS__)
where pack_args(...) - is a macro too. How should I change this code to handle the only fmt_string presence scenario?
log("Some message here");
In P99 I have two macros
You can use this to determine if your argument has a comma (so there are more arguments than your format) or not (only a format). You can then use that to construct a call to one of two macros:
You cannot do this at all with a variadic macro in standard C. The standard explicitly specifies that in the invocation of a variadic macro "there shall be more arguments in the invocation than there are parameters in the macro definition (excluding the ...)" (C2011, 6.10.3/4). You could allow the macro to be used with just one argument by changing it to ...
... but then you could not separate the format string from the other arguments -- at least not without re-introducing the same problem you have now.
You'll need to use a bona fide function if you need to support a zero-length variable argument list.