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?

a3f
  • 8,517
  • 1
  • 41
  • 46
beakr
  • 5,709
  • 11
  • 42
  • 66
  • Well, if thinking "available on OS X/iOS and Linux", don't you want to check for POSIX-availablity instead? –  May 04 '13 at 20:41
  • Possible duplicate of [how to use #ifdef with an OR condition?](https://stackoverflow.com/questions/9682593/how-to-use-ifdef-with-an-or-condition) – Itay Grudev May 09 '19 at 19:51

2 Answers2

34

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
john
  • 85,011
  • 4
  • 57
  • 81
3

In my C++ there is.

#if defined(__APPLE__) || defined(__linux)
  // ...
#endif
masoud
  • 55,379
  • 16
  • 141
  • 208