[c] how to use #ifdef with an OR condition?

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?

This question is related to c macros

The answer is


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