how to use #ifdef with an OR condition?
Asked Answered
C

2

302

Sorry for asking very basic question. I would like to set OR condition in #ifdef directive.? How to do that ? I tried

#ifdef LINUX | ANDROID
...
..
#endif 

It did not work? What is the proper way?

Colton answered 13/3, 2012 at 10:51 Comment(2)
If you're using | for "or" in your C conditionals too, you're doing it wrong.Garpike
Hence the visit to SO to find out how to do it not-wrong.Sauer
C
613

Like this

#if defined(LINUX) || defined(ANDROID)
Carmella answered 13/3, 2012 at 10:52 Comment(0)
N
70

OR condition in #ifdef

#if defined LINUX || defined ANDROID
// your code here
#endif /* LINUX || ANDROID */

or-

#if defined(LINUX) || defined(ANDROID)
// your code here
#endif /* LINUX || ANDROID */

Both above are the same, which one you use simply depends on your taste.


P.S.: #ifdef is simply the short form of #if defined, however, does not support complex condition.


Further-

  • AND: #if defined LINUX && defined ANDROID
  • XOR: #if defined LINUX ^ defined ANDROID
Nude answered 6/3, 2019 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.