I have a debug macro that I use for quick and dirty outputs. I've been trying to determine how to make code compile clean on gcc 5.4. It doesn't give any issues on earlier version of gcc (4.x) or clang (11.0.3). The error is this:
main.c: In function ‘main’:
main.c:4:38: warning: too many arguments for format [-Wformat-extra-args]
do { if (1){ fprintf(stdout, "debug:%s:%04d:%s: " fmt, __FILE__, \
^
main.c:10:2: note: in expansion of macro ‘DEBUGPRINT’
DEBUGPRINT("How to have no arguments?\n", NULL);
The code that I've been using to try to determine how to fix this is:
#include <stdio.h>
#define DEBUGPRINT(fmt, ...) \
do { if (1){ fprintf(stdout, "debug:%s:%04d:%s: " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);} } while (0)
int main(int argc, char *argv[])
{
DEBUGPRINT("nums: %04i, %04i\n", 0x1234,0x5678);
DEBUGPRINT("How to have no arguments?\n", NULL);
return(0);
}
As one can see, if I have arguments, there's not problem. It's only if I have a message that's does not have arguments. I guess that I could pass a "\n" with '%s', but I was just curious if there was a way to handle the NULL.