Objective-C preprocessor directive for 'if not'

Undistraction picture Undistraction · Jun 4, 2012 · Viewed 24.6k times · Source

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
}

Answer

CarlJ picture CarlJ · Jun 4, 2012

you could try:

#if !(SOME_VARIABLE)
   // Do something
#endif