Reputation:
Sorry I know this is basic, but perhaps it doesn't exist or I'm not googling the right words.
Is there and an if not
(is that ifndef
?) an AND
and an OR
so I could do something like:
if not DEBUG and MACOS
Upvotes: 2
Views: 770
Reputation: 3825
#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
Upvotes: 1
Reputation: 146910
Check out the Boost preprocessing library. It can accomplish a large number of tasks using the preprocessor.
Upvotes: 0
Reputation: 155323
#if !(defined(DEBUG) && defined(MACOS))
or
#if !defined(DEBUG) && !defined(MACOS)
depending on what you're trying to evaluate.
Upvotes: 1
Reputation: 2842
#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
Upvotes: 3
Reputation: 12515
#if !DEBUG && MACROS
or
#if !DEBUG & !MACROS
depending on what you are looking for. defined() can also help
#if !defined(DEBUG) && defined(MACROS)
Upvotes: 2
Reputation: 96233
I think something like #if !defined(DEBUG) && defined(MACOS)
should do it.
Upvotes: 13
Reputation: 40849
#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.
Upvotes: 3