I understand how to use a preprocessor directive like this:
#if SOME_VARIABLE // Do something #else // Do something else #endif
But what if I only want to do something IF NOT SOME_VARIABLE.
Obviously I still could do this:
#if SOME_VARIABLE #else // Do something else #endif
. . . leaving the if empty, But is there a way to do:
#if not SOME_VARIABLE // Do something #endif
Apple documentation here suggests not, but this seems like a very basic need.
Basically I want to do the preprocessor equivalent of:
if(!SOME_VARIABLE)( { // Do Something }
#define name value , however, is a preprocessor command that replaces all instances of the name with value . For instance, if you #define defTest 5 , all instances of defTest in your code will be replaced with 5 when you compile. Follow this answer to receive notifications.
#ifdef MACRO or #if defined (MACRO) checks whether the macro is defined, with or without value. #if MACRO substitutes the macro definition; if the macro is not defined then it substitutes 0. It then evaluates the expression that it find.
8.2 Conditional Compilation (#if, #ifdef, #ifndef, #else, #elif, #endif, and defined) Six directives are available to control conditional compilation. They delimit blocks of program text that are compiled only if a specified condition is true. These directives can be nested.
you could try:
#if !(SOME_VARIABLE) // Do something #endif
Are you trying to check if something is defined or not? If yes, you can try:
#ifndef SOME_VARIABLE
or
#if !defined(SOME_VARIABLE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With