Every time, I invoke the below C debug macro, I have to pass some argument. Else compilation fails.
#include <stdio.h>
#include <stdlib.h>
#define debug(fmt, ...)\
do{\
fprintf(stdout, "%s(%d) : " fmt, __FUNCTION__, __LINE__, __VA_ARGS__);\
}while(0)
int
main()
{
debug("Debug 1");
}
Here is the compilation error :
test.c:12:5: error: expected expression debug("Debug 1"); ^ test.c:6:70: note: expanded from macro 'debug' fprintf(stdout, "%s(%d) : " fmt, FUNCTION, LINE, VA_ARGS);\ ^ 1 error generated.
If I invoke the same macro with an argument :
debug("Debug 1 %s", "");
It compiles fine with no issues. Is is because of the compiler ? Does it work in latest compiler ?