I have a piece of code which I want to include if either of two macros are defined
#ifdef MACRO1 || MACRO2
void foo()
{
}
#endif
How do I accomplish this in C?
Here the NOT version if needed:
#if !defined(MACRO1) && !defined(MACRO2)
...
#endif
Besides #ifdef
, the preprocessor supports the more general #if
instruction; actually, #ifdef MACRO
is a shortcut for #if defined(MACRO)
, where defined
is a "preprocessor function" that returns 1 if the macro is defined; so, you can do:
#if defined(MACRO1) || defined(MACRO2)
void foo()
{
}
#endif
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