#include <stdio.h>
#define STR(x) #x
#define STR2(x) STR(x)
#define LINE_FILE ("Line " STR2(__LINE__) " of file " STR2(__FILE__))
int main(void)
{
const char *str = LINE_FILE;
printf("%s\n", str);
return 0;
}
Is this the only definition scheme that will make STR(x) to print the actual LINE and FILE???
__FILE__is already a string literal: you don’t need to useSTR2here.You should also probably remove the parentheses from the macro so that it can be concatenated with other string literals, if you wanted to do that: