1: //conditional_compilation.cpp
2: //Illustrates the defining of different macros to control the inclusion
3: //and compilation of different code sections, depending on which macro
4: //is defined at the time of compilation.
6: /*
7: To test this program, first activate comment //1 below, then comment //2,
8: and finally activate both comment //1 and comment //2 simultaneously, and
9: observe the output on each of the three occasions.
10: */
12: #include <iostream>
13: using namespace std;
15: //#define SECTION1 //1
16: //#define SECTION2 //2
18: int main()
19: {
20: #ifdef SECTION1
21: cout << "\nIf the macro SECTION1 is defined, then this cout "
22: "statememt will be included in\nthe source code from this file "
23: "to be be compiled. If SECTION1 is not defined,\nthis code will "
24: "be ignored when this file is compiled.\n";
25: #endif
27: #ifdef SECTION2
28: cout << "\nIf the macro SECTION2 is defined, then this cout "
29: "statememt will be included in\nthe source code from this file "
30: "to be be compiled. If SECTION1 is not defined,\nthis code will "
31: "be ignored when this file is compiled.\n";
32: #endif
34: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
35: }