Say we have main.c:
#define f() { \
foo(); \
bar(); \
}
#define F() { \
f(); \
f(); \
}
F();
Now if we gcc -E main.c -o main.i, in main.i there is:
# 1 "main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "main.c"
# 11 "main.c"
{ { foo(); bar(); }; { foo(); bar(); }; };
What if I don't want inner macros (like f()) to be expanded. How can I get something like:
# 1 "main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "main.c"
# 11 "main.c"
{ f(); f(); };
Also if it's possible then how can I tune expansion depth?
Simple answer (at least for the C preprocessors I know):
You cannot - Not in the general case. Macros are expanded by recursion and the recursion depth cannot be set with, for example, GNU cpp.
In specific cases where the "outer" and the "inner" macro are defined in different files you might be able to somewhat achieve what you want by simply not including (or providing an empty include of) the file that defines the "outer" definition and feeding the file with the "inner" definition directly into cpp.
I do, however, have a cpp implementation for an embedded system that actually does print every recursion step to stderr when executed with the highest verbosity ("-vvv"), although that doesn't help you with gcc/cpp - But this at least shows that something like you want is technically possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With