Reputation: 35793
I was wondering if it was possible to define a macro in C++ that defines another macro that can be used in later code. Is this possible, or is the preprocessor used by g++ too limited for this?
Upvotes: 0
Views: 200
Reputation: 7705
You can do something like this, its not exactly what you are looking for, but it might help.
#ifdef ENABLE_MACRO_1
#define PRINT_MACRO(varName) \
std::cout<<varName<<std::endl;
#else
#define PRINT_MACRO(varName) \
//do nothing
#endif
So you can define a macro depending on another preprecursor condition which was defined defined.
Upvotes: 1
Reputation: 82041
The preprocessor makes only one pass over the source code, so this is not possible. However, you could use an external tool to perform some preprocessing ahead of compilation, like m4.
Upvotes: 1
Reputation: 68571
No, you cannot define a macro within the expansion of another macro.
Upvotes: 5