How do I check if one of multiple macros is defined in a single #ifdef?
Asked Answered
C

2

18

I have some C++ code, and want to perform an action if the __APPLE__ or __linux macros are defined.

If I did it as a normal if conditional, it would be easy using ||:

if (something || something) { .. code .. }

But as of what I know there is no || operator for #ifdef statements. How would I check if __APPLE__ or __linux is defined using a single #ifdef statement?

Chivers answered 4/5, 2013 at 20:37 Comment(2)
Well, if thinking "available on OS X/iOS and Linux", don't you want to check for POSIX-availablity instead?Chub
Possible duplicate of how to use #ifdef with an OR condition?Gehrke
P
36

You can't in a single #ifdef would a single #if do instead?

#if defined(__APPLE__) || defined(__linux)

this also works if you prefer

#if defined __APPLE__ || defined __linux
Physiognomy answered 4/5, 2013 at 20:39 Comment(0)
C
3

In my C++ there is.

#if defined(__APPLE__) || defined(__linux)
  // ...
#endif
Conover answered 4/5, 2013 at 20:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.