// Oldham, Jeffrey D. // 2000Feb21 // CS1321 // Example of Conditional Compilation // This one piece of code produces two different programs depending on // whether you tell the compiler that "DEBUG" is defined. If it is // not defined, the debugging code will not be part of the program. // If it is defined, the debugging code will be part of the program. // To define "DEBUG", you must compile with a command like // g++ -DDEBUG debug.cc // Following the "-D" is the term you want to define. // Using "g++ debug.cc" will cause the debugging code to be omitted. #include #include // has EXIT_SUCCESS int main() { cout << "Hello, world.\n"; #if defined(DEBUG) // Note the syntax. Lines starting with "#" must appear on lines by // themselves and delimit the region of code that is conditionally // included. cout << "This debugging message is printed only during debugging.\n"; #endif cout << "Hello, world.\n"; return EXIT_SUCCESS; }