C macro stringification
I am using gcc to compile C99 code. I want to write a macro which will
return a string containing the function name and line number.
This is what I have:
#define INFO_MSG __FILE__ ":"__func__"()"
However, when I compile code which attempts to use this string, for example:
char buff[256] = {'\0'}
sprintf(buff, "Something bad happened here: %s, at line: %d", INFO_MSG,
__LINE__);
printf("INFO: %s\n", buff);
I get the following error message:
error: expected ')' before '__func__'
I have tracked the problem down to the macro. as when I remove __func__
from the macro, the code compiles correctly.
How do I fix the macro, so that I can include the predefined __func__
macro in my string?
No comments:
Post a Comment