xHarbour Reference Documentation > Preprocessor Reference xHarbour Developers Network  

#ifndef

Compiles a section of code depending on the absence of a #define constant.

Syntax

#ifndef <constant>
  <statements1>
[ #else
  <statements2> ]
#endif

Arguments

<constant>
This is the symbolic name of a #define constant.
<statements1> .. <statements2>
These are program statements to include or exclude in the preprocessor output. <statements1> is included when <constant> is not #define'd. Otherwise, the statements following #else, if present, are included.

Description

The #ifdef..#else..#endif directives are used for conditional compilation. They work similar to the IF..ELSE..ENDIF statements, but are resolved by the preprocessor, rather than the compiler. #ifndef tests if a #define constant does not exist. When the constant is undefined, the statements following #ifndef are included in the preprocessor output. When the constant does exist, the statements folowing #else, if present, are used. #endif closes the conditional compilation block.

Info

See also:#define, #if, #ifdef
Category: Preprocessor directives

Example

// The example demonstrates a common technique used to avoid multiple
// inclusion of an #include file. If, by accident, an include file is
// included more than once, the directives are skipped by the preprocesor
// since the #define constant MY_CH_FILE is created on first inclusion.

   #ifndef  MY_CH_FILE
      #define MY_CH_FILE

      <preprocessor directives>
   #endif

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe