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?
-
1It's nor the "preprocesor used by g++" that isn't powerful enough, it's the C++ language itself that does not allow this. If you explained what you want to accomplish, I'm sure people here could come up with a solution.Lindydancer– Lindydancer2012-01-20 15:06:22 +00:00Commented Jan 20, 2012 at 15:06
-
How would you be "limited" by this? Share what you're trying to accomplish.Drew Dormann– Drew Dormann2012-01-20 15:31:39 +00:00Commented Jan 20, 2012 at 15:31
Add a comment
|
4 Answers
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.
Comments
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.