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
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
#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.
I think something like #if !defined(DEBUG) && defined(MACOS)
should do it.
#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
#if !(defined(DEBUG) && defined(MACOS))
or
#if !defined(DEBUG) && !defined(MACOS)
depending on what you're trying to evaluate.
Check out the Boost preprocessing library. It can accomplish a large number of tasks using the preprocessor.
#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