Show/Hide Toolbars

XSharp

Purpose

Build a section of code if a constant is FALSE, 0, or not defined.

Syntax

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

Arguments

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

Description

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

Note: You can use #ifndef 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 #ifndef.  Since the constant lDebug is set to FALSE, the code between the #ifndef and #else statements will be built, and the code between the #else and #endif statements will be ignored:

 

DEFINE lDebug := FALSE
 
FUNCTION Start()
 #IFNDEF lDebug
         <Optimized version OF code>...
 #ELSE
         <Debugging version OF code>...
 #ENDIF

 

Changing the DEFINE statement as follows will build the code between the #else and #endif statements instead.

DEFINE lDebug := TRUE

See Also

#ifdef, DEFINE