Um, no. Preprocessing happens before the code is even compiled. It exists in a completely different universe from the executing program. One thing you can do, is run just the pre-processing step and examine the output (use the gcc switch -E
to print the preprocessor output).
About the most you can do is to redirect this to a file, and then read the file in the program.
On further thought, let me back-off from "no", and change it to "maybe". Take a look at this other answer of mine, that implements a "foreach" macro for variadic macros.
So, using APPLYXn
(and, implicitly, PPNARG
), you could apply a STR(x) #x
macro to the args like this (n.b. as written, APPLYXn
can handle up to 15 arguments):
#define X(x) #x
#define ERROR_MESSAGE(priority, fmt, ...) \
"do {MODULE_LOG(" X(priority) X(fmt) APPLYXn(__VA_ARGS__) ");} while(0)"
int main() {
printf("%s\n", ERROR_MESSAGE(3, "%d", 5) );
return 0;
}
gcc -E
produces
# 1 "strvar.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "strvar.c"
# 71 "strvar.c"
int main() {
printf("%s\n", "do {MODULE_LOG(" "3" "\"%d\"" "5" ");} while(0)" );
return 0;
}
And the compiler will concatenate all these string literals into one string.