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?
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?
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
Here the NOT version if needed:
#if !defined(MACRO1) && !defined(MACRO2)
...
#endif
#if defined(Macro 1) + defined(Macro 2) == 1
<Code>
#endif
© 2022 - 2024 — McMap. All rights reserved.