Sandra-24
asked on
How do you nest one #define inside another #define?
More specifically how would one include a #ifdef-#endif in a macro so that it will be evaluated not where the macro is defined, but where the macro is invoked.
#define macro #ifdef CONSTANT dosomething() #endif
macro; //this will do nothing
#define CONSTANT
macro; //this will do something
Thanks,
-Sandra
#define macro #ifdef CONSTANT dosomething() #endif
macro; //this will do nothing
#define CONSTANT
macro; //this will do something
Thanks,
-Sandra
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I guess what Sandra wants to do is turn the marco ON and OFF in multiple places in the file.
such as,
void main()
{
#undef CONSTANT
macro; //this will do nothing
#define CONSTANT
macro; //this will do something
}
such as,
void main()
{
#undef CONSTANT
macro; //this will do nothing
#define CONSTANT
macro; //this will do something
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Thomas, that's a neat workaround. I didn't think of using an include file which is sortof like a macro to begin with. You can include it in many places in your code and you can add all the #ifdefs you want to it:)
-Sandra
-Sandra
#ifdef CONSTANT
#define macro DoSomething();
#else
#define macro
#endif
Using:
macro
If CONSTANT is defined, preprocessor replaces this line to
DoSomething();
If CONSTANT is undefined, preproceccor replaces this line with empty line.