defined

From Appmethod Topics
Jump to: navigation, search

Go Up to Conditional Compilation Overview Index

Syntax

defined identifier 
defined ( identifier ) 

Description

Use the defined operator to test if an identifier was previously defined using #define.

The preprocessor operator defined can be used in constant expressions with the following syntax:

defined [(] identifier [)] 

The defined operator is only valid in #if and #elif expressions like these:

#if defined identifier
#elif defined ( identifier )

Here the defined constant expression evaluates to 1 (true) if a previously defined identifier has not been undefined (using #undef). Otherwise, it evaluates to 0 (false).

Defined performs the same function as #ifdef. For example,

#if defined(mysym)

is the same as

#ifdef mysym

The advantage is that you can use defined repeatedly in a complex expression following the #if directive. For example,

#if defined(mysym) && !defined(yoursym)

See Also