I am having issues while trying to pass a macro constant as an argument to a macro function.
Consider the following code -
#define ERROR 10
#define MAIN "Main:"
#define LOG(lvl,mod,fmt,...) \
char msg[256] = {0}; \
snprintf(msg, 256, "%s: %d: "fmt,mod,lvl,##__VA_ARGS__)
int main()
{ ....
LOG(ERROR, MAIN, "This is a log statement.\n"); // Doesn't compile
LOG(10, "Main:", "This is a log statement.\n"); // Compiles
....
}
The second log statement compiles but the first log statement generate the following compilation error -
error: expected `)' before ‘;’ token
error: expected primary-expression before ‘,’ token
error: expected `;' before ‘)’ token
Why is this happening? I want to be able to define a set of Logging levels and Modules constants, and use them while invoking the LOG() macro.