16.3 CONDITIONAL COMPILATION

It is possible to compile a certain part of program (source code) conditionally. Certain pre-processor directives help us in this regard. One such directive is #ifdef. It stands for if defined.

A typical directive looks as follows.

#ifdef stdout

The syntax rules want the word #ifdef to start in first column. It is worth noting is that preprocessor directives are not format free. They do not use semicolon to terminate.

This pre-processor directive tests the symbol appearing next. If this symbol is defined at this stage, the code following this directive till directive #endif will be compiled.

Here the symbol is stdout. It is defined in header file stdio.h. If we have included this file in the program, then this symbol ...

Get Object Oriented Programming with C++, Second Edition 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.