I am trying to print logs into a file by writing macros. My macro looks like as shown below:
#define LOG(fmt,...){\
FILE *F;\
F = fopen("output.txt","a");\
fprintf(F,fmt " %s %d",__VA_ARGS__,__FILE__,__LINE__);}
And I plan to call LOG in the following format:
LOG("values are : %d %d",num1,num2);
But when I compile I get the error
error: expected expression before ‘,’ token
fprintf(F,fmt " %s %d",__VA_ARGS__,__FILE__,__LINE__);}
Can someone please explain where I am going wrong?
__FILE__
is achar[]
, not aint
, right? And unrelated to your problem, I sincerely hope there is anfclose()
somewhere in the real code, as otherwise you're leaking stream pointers like a sieve leaks rain water.