Functions and Directives

Directive #ifndef Foundation

Compiles code when a symbol is not defined

Syntax
#ifndef <Symbol>
   <SourceCode>...
[ #else
   <SourceCode>...
]
#endif
Parameters
<Symbol>
<Symbol> designates a preprocessor constant that, if not defined, causes a section of code to be recognized by the preprocessor.
Description

The directives #ifndef...#else...#endif form a control structure for the preprocessor. When the preprocessor constant <Symbol> has not been defined previous to the preprocessor encountering the #ifndef directive, the preprocessor translates and outputs the source code located between the directives #ifndef and #else to the intermediary file. If no #else directive is present, the preprocessor translates and outputs the source code located between the directives #ifndef and #endif.

#ifndef provides support for conditional compilation. The preprocessor translates the source code subsequent to the directive #ifndef only when the preprocessor constant <Symbol> has not been previously defined. If this constant has been defined the preprocessor translates the source code which is between the #else and #endif directives. Whichever block of code the preprocessor ignores does not get translated and output to the intermediary file, and thus does not get compiled.

Examples
#ifndef used to implement language versions
// The example shows how different language versions can be 
// generated for a program depending on a preprocessor constant. 
// The program example would be compiled as a German version. 
// It also shows how to ensure that a constant is defined. 

#define GERMAN_LANGUAGE 

PROCEDURE Main 

   #ifndef GERMAN_LANGUAGE 
      ? "This is the English version of the program" 
   #else 
      ? "Das ist die deutsche Version des Programms" 
   #endif 

   #ifndef LOGIN_PATH 
      #define  LOGIN_PATH    CurDir() 
   #endif 

   USE ( LOGIN_PATH+ "\LOGBOOK" ) NEW 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.