1: #include <iostream> 
   2: 
   3: #define DEBUG 
   4: #if defined ( DEBUG ) 
   5: #define DEBUG_CODE( code_to_put_into_source ) { code_to_put_into_source } 
   6: #else 
   7: #define DEBUG_CODE( code_to_put_into_source ) 
   8: #endif 
   9: 
  10: 
  11: /**
  12: * This is a test file that shows how to do conditional compilation with the 
  13: * help of preprocessor macros:
  14: *
  15: * if DEBUG is defined all the DEBUG_CODE codes get's compiled into the 
  16: * executable, else it is ignored.
  17: *
  18: */
  20: int main()
  21: {
  22: #if defined ( DEBUG ) 
  23: cout << "\nDEBUG is defined -> here comes the debugging code:\n" << endl;
  24: #else 
  25: cout << "\nDEBUG is not defined -> no debugging code :-]\n" << endl;
  26: #endif 
  27: 
  28: DEBUG_CODE
  29:     (
  30:     cerr << "This comes from the debugging macro !" << endl;
  31:     cerr << "You can use \"#define DEBUG\" in the header file, " << endl;
  32:     cerr << "or use the compiler switch \"-DDEBUG\" to change to the debuggging mode !" << endl << endl;
  33:     )
  34: 
  35: return 0;
  36: }