#ifdef and #ifndef

From RAD Studio
Jump to: navigation, search

Go Up to Conditional Compilation Directives (C++)


Syntax

#ifdef identifier
#ifndef identifier

Description

The #ifdef and #ifndef directives are the same as the #if directive with defined (identifier) operator:

#if defined identifier
#if !defined identifier

You can use the #ifdef and #ifndef directives instead of the #if defined identifier expressions. However, the #if defined identifier expressions are preferred. The #ifdef and #ifndef directives are provided only for compatibility with previous versions of the language.

The #ifdef and #ifndef conditional directives let you test whether an identifier is currently defined or not. That is, whether a previous #define command has been processed for that identifier and is still in force. The line

#ifdef identifier

has exactly the same effect as

#if 1

if identifier is currently defined, and the same effect as

#if 0

if identifier is currently undefined.

An #ifndef evaluates "true" for the "not-defined" identifier, so the line

#ifndef identifier

has exactly the same effect as

#if 0

if identifier is currently defined, and the same effect as

#if 1

if identifier is currently undefined.

The syntax thereafter follows that of the #if, #elif, #else, and #endif.

An identifier defined as NULL is considered to be defined.

See Also