Show/Hide Toolbars

XSharp

Purpose

Build a section of code if a constant exists and is not equal to FALSE or 0.

 

Syntax

#ifdef <idConstant>
 <Statements>...
[#else]
 <Statements>...
#endif

Arguments

<idConstant>The name of a constant whose existence is being verified.

 

Description

#ifdef...#endif lets you perform a conditional build by identifying a section of source code to include if a specified constant exists and is not equal to FALSE or 0.  The #else statement specifies the code to include if the #ifdef condition fails, and the #endif terminates the conditional build block.

Note: You can use #ifdef with compiler entities other than constants, such as functions and globals.  In these cases, the statement tests for existence only, and does not look at the value of the entity.

 

Examples

This code fragment is a general skeleton for a conditional build with #ifdef.  Because the lDemo constant is defined as TRUE, the code between the #ifdef and #endif statements will be built:

 

DEFINE lDemo := TRUE
FUNCTION Start()
 #IFDEF lDemo
         <Demo-specific statements>...
 #ENDIF
 ...
 

 
To build the real (non-demo) version of this application, you would change the DEFINE statement to:

 
DEFINE lDemo := FALSE

 

See Also

#ifndef, DEFINE