user1311286
user1311286

Reputation:

C Pre-processor directives, Is this correct syntax? #Ifdef foo || bar

I have a pre-processor directive as such,

//#define SPEC_CONTROL  // Is not defined, but can be if need be
#define SPEC_A_CONTROL  // Is defined

#ifdef SPEC_CONTROL || SPEC_A_CONTROL
    ; // do something
#else
    ; // do something else
#endif

Is it correct syntax to use the || in the manner I did?

Upvotes: 0

Views: 153

Answers (2)

A. Santavicca
A. Santavicca

Reputation: 29

You can use boolean logic in a C preprocessor directive by using the if defined directive.

See this post for more information: C Preprocessor testing definedness of multiple macros

Upvotes: 1

Ingo Leonhardt
Ingo Leonhardt

Reputation: 9904

I can assure yout that at least

#if defined(SPEC_CONTROL) || defined(SPEC_A_CONTROL)

works on Windows and several UNIX platforms. Im not sure about

#ifdef SPEC_CONTROL || SPEC_A_CONTROL

Upvotes: 1

Related Questions