I want to create a macro that prints some info and takes any number of arguments to print additional message(s) if needed.
Here's a code snippet im talking about:
#include <stdio.h>
#define print(msg, ...) \
printf("Line: %d File %s "## msg, __LINE__ , __FILE__, __VA_ARGS__);
int main()
{
print("Msg: %d", 13);
print("Msg: %d, Msg2: %d", 123, 234);
}
Here's an error I'm getting:
main.cpp:12:9: error: pasting ""Line: %d File %s "" and ""Msg: %d"" does not give a valid preprocessing token
printf("Line: %d File %s "## msg, __LINE__ , __FILE__, __VA_ARGS__);
What am I doing wrong?