Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C preprocessor directive for 'if not'

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 } 
like image 440
Undistraction Avatar asked Jun 04 '12 11:06

Undistraction


People also ask

What does #define do in Objective C?

#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.

What is #ifdef Objective C?

#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.

What purpose do #if #elseif #else #endif #ifdef #ifndef serve?

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.


2 Answers

you could try:

#if !(SOME_VARIABLE)    // Do something #endif 
like image 73
CarlJ Avatar answered Sep 30 '22 23:09

CarlJ


Are you trying to check if something is defined or not? If yes, you can try:

#ifndef SOME_VARIABLE

or

#if !defined(SOME_VARIABLE)

like image 27
xuzhe Avatar answered Sep 30 '22 22:09

xuzhe