Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor checking defined

I can check predefined value like:

#ifdef SOME_VAR
  // Do something
#elif
  // Do something 2
#endif

If I have to check 2 values instead of 1. Are there any operator:

#ifdef SOME_VAR and SOME_VAR2
  // ...
#endif

Or I have to write:

#ifdef SOME_VAR
   #ifdef SOME_VAR2
      // At least! Do something
   #endif
#endif
like image 889
Max Frai Avatar asked Jul 02 '26 06:07

Max Frai


1 Answers

The standard short-circuiting and operator (&&) along with the defined keyword is what is used in this circumstance.

#if defined(SOME_VAR) && defined(SOME_VAR2)
    /* ... */
#endif

Likewise, the normal not operator (!) is used for negation:

#if defined(SOME_VAR) && !defined(SOME_OTHER_VAR)
    /* ... */
#endif
like image 64
Mark Rushakoff Avatar answered Jul 03 '26 19:07

Mark Rushakoff