xHarbour Reference Documentation > Preprocessor Reference |
Compiles a section of code depending on the presence of a #define constant.
#ifdef <constant> <statements1> [ #else <statements2> ] #endif
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. #ifdef tests if a #define constant exists. When the constant is defined, the statements following #ifdef are included in the preprocessor output. When the constant does not exist, the statements folowing #else, if present, are used. #endif closes the conditional compilation block.
See also: | #define, #if, #ifndef, #undef |
Category: | Preprocessor directives |
// The example demonstrates how to implement an extended error // checking in the DEBUG version of a program. When DEBUG is not // defined, all ErrCheck() pseudo-functions are removed from // the PRG code by the preprocessor. #define DEBUG #ifdef DEBUG #xtranslate ErrCheck(<errCond>,<msg>) => ; IF (<errCond>) ;; IF Alert( "Error:;"+<(msg)>,{"Continue","Ouit"}) <> 1 ;; QUIT ;; ENDIF ;; ENDIF #else #xtranslate ErrCheck(<errCond>,<msg>) => #endif PROCEDURE Main( cParams ) ErrCheck( Empty(cParams), "Command line params missing" ) ? "Error check OK" RETURN
http://www.xHarbour.com