Name
The defined operator
Synopsis
The defined
operator can be used to verify whether
a given macro name is currently defined.
Syntax:
defined (name
)
The operator yields a non-zero value if a valid definition exists for
name
; otherwise it yields the value
0
. A macro name defined by a
#define
directive remains defined until it is
cancelled by an #undef
directive. A macro name is
considered to be defined even if no replacement text is specified
after name
in the
#define
directive.
The defined
operator is typically used in
#if
and #elif
directives:
#if defined(VERSION ... #endif
Unlike the #ifdef
and #ifndef
directives, the defined
operator yields a value
that can be used in a preprocessor expression:
#if defined(VERSION) && defined(STATUS ... #endif
Get C Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.