how to use #ifdef with an OR condition?

CMacros

C Problem Overview


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?

C Solutions


Solution 1 - C

Like this

#if defined(LINUX) || defined(ANDROID)

Solution 2 - C

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWhoamiView Question on Stackoverflow
Solution 1 - CzvrbaView Answer on Stackoverflow
Solution 2 - CMinhas KamalView Answer on Stackoverflow