I want to write a variadic macro that somehow knows the names of the arguments passed. For example:
The code:
int x = 2;
float f = 4.6;
char c = 'A';
char* str = "Bla bla";
PRINT("%d %f %c %s", x, f, c, str); // calling the macro
shall produce the output
x=2 f=4.6 c=A str=Bla bla.
Hope someone knows the answer to that.
Read carefully the documentation of cpp. In particular, about macro arguments, stringification, concatenation, and variadic macros. It is well explained there.
You probably might not be able to achieve exactly what you want, because you need to split the format string.
Perhaps lower your goals (e.g. accept only one argument for
PRINT, see this or that answers) or consider using a more powerful preprocessor like GPP.You could also perhaps customize GCC (by adding your builtins) with e.g. MELT but that is probably not worth the weeks of efforts (for a newbie) required to do so.