Conditional compilation

As explained in Chapter 1, Starting with C++, when your C++ program is compiled there is a pre-compilation step that collates all the file included in a C++ source file into a single file, which is then compiled. The pre-processor also expands macros and, depending on the value of symbols, includes some code and exclude others code.

In its simplest form, conditional compilation brackets code with #ifdef and #endif (and optionally using #else), so that the code between these directives is only compiled if the specified symbol has been defined.

    #ifdef TEST        cout << "TEST defined" << endl;         #else        cout << "TEST not defined" << endl;     #endif

You are guaranteed that only one of these lines will be compiled, and you are ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.