Initially I thought I needed this, but I eventually avoided it. However, my curiosity (and appetite for knowledge, hum) make me ask:
Can a preprocessor macro, for instance in
#include "MyClass.h"
INSTANTIATE_FOO_TEMPLATE_CLASS(MyClass)
expand to another include, like in
#include "MyClass.h"
#include "FooTemplate.h"
template class FooTemplate<MyClass>;
?
The LENGTH and BREADTH are called the macro templates. The values 10 and 20 are called macro expansions. Advertisements. When the program run and if the C preprocessor sees an instance of a macro within the program code, it will do the macro expansion. It replaces the macro template with the value of macro expansion.
TABLESIZE is expanded first to produce BUFSIZE, then that macro is expanded to produce the final result, 1024.
Macro Substitution is a process where an identifier is replaced by a predefined string or a value. "#define" is the Macro Substitution directive in C.
Macro definition and Expansion A macro consists of name, set of formal parameters and body of code. The use of macro name with set of actual parameters is replaced by some code generated by its body. This is called macro expansion.
I believe that cannot be done, this is because the pre-processor is single pass. So it cannot emit other preprocessor directives.
Specifically, from the C99 Standard (6.10.3.4 paragraph 3):
3 The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one, ...
Interestingly enough, This is why the unary _Pragma
operator was added to c99. Because #pragma
could not be emited by macros, but _Pragma
can.
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