Hard to tell what you actually want here. Remember, macros are essentially just a glorified copy and paste, so this macro is not very useful:
#define LINE_FILE ("Line %d of file %s", __LINE__, __FILE__)
I think what you are looking for is a macro that calls printf
with __LINE__
and __FILE__
. Something like this should do it:
#define LINE_FILE printf("Line %d of file %s", __LINE__, __FILE__)
Or maybe you want to store it in a buffer for something else with a "function-like macro":
#define LINE_FILE(buf_, n_) \
snprintf(buf_, n_, "Line %d of file %s", __LINE__, __FILE__)
int main()
{
char buf[50];
LINE_FILE(buf, sizeof(buf));
}