I am trying to implement a function macro in C that adds "DEBUG:" to the argument and passes its arguments to printf:
#define DBG(format, ...) printf("DEBUG: " #format "\n", __VA_ARGS__)
This gives me this error in gcc:
src/include/debug.h:4:70: error: expected expression before ')' token #define DBG(format, ...) printf("DEBUG: " #format "\n", __VA_ARGS__) ^
Presumably, it should scribble the format and pass arguments to the variable printf, but so far I can not get through this error.
EDIT
After discarding the building arguments and double hashing ( ## ) __VA_ARGS__ I now have this error:
src/lib/cmdlineutils.c: In function 'version': src/lib/cmdlineutils.c:56:17: warning: ISO C99 requires rest arguments to be used [enabled by default] DBG("version()");
Should I put a comma after the argument?
DBG("version()",);
For reference, DBG () now looks like this:
#define DBG(format, ...) printf("DEBUG: " format "\n",
source share