views:

129

answers:

7

Sorry I know this is basic, but perhaps it doesn't exist or I'm not googling the right words is there and a if not (is that ifndef?) an AND and an OR? so I could do something like

if not DEBUG and MACOS

thanks

+3  A: 

#ifndef and #if do different things so it depends on what you want. #ifndef is true when there is no defined preprocessor symbol that matches the name following. #if is true when the following preprocessor expression evaluates to non-zero.

You can use the standard && and || operators.

Noah Roberts
+10  A: 

I think something like #if !defined(DEBUG) && defined(MACOS) should do it.

Mark B
+1  A: 
Michael Dorgan
+3  A: 
#if !defined(DEBUG) && defined(MACOS)
#error "Ouch!"
#endif

tests, if those macros/values are defined (even set to 0 means defined). Leave out the "defined()" and test again a value, depending on your macros, like

#if DEBUG==0 && MACOS==1
#error "Spam!"
#endif
zerm
+1  A: 

#if !(defined(DEBUG) && defined(MACOS))

or

#if !defined(DEBUG) && !defined(MACOS)

depending on what you're trying to evaluate.

ShadowRanger
A: 

Check out the Boost preprocessing library. It can accomplish a large number of tasks using the preprocessor.

DeadMG
+2  A: 

#if, #else and #endif are general. Use #define to declare and #undef to undeclare. Use #ifdef to check if is declared and #ifndef to check, if is not declared.

Example:

#ifndef LABEL
#define LABEL some_value // declares LABEL as some_value
#else
#undef LABEL // undeclare previously declared LABEL...
#define LABEL new_value // to declare a new_value
#endif
AOI Karasu