how to use #ifdef with an OR condition?
CMacrosC 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