298

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?

MD XF
  • 7,860
  • 7
  • 40
  • 71
Whoami
  • 13,930
  • 19
  • 84
  • 140

2 Answers2

605

Like this

#if defined(LINUX) || defined(ANDROID)
zvrba
  • 24,186
  • 3
  • 55
  • 65
66

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
Minhas Kamal
  • 20,752
  • 7
  • 62
  • 64