Conditional Compilation

Even if macros go completely out of favor, the C++ preprocessor allows you to conditionally compile code, depending on the environment. For example, usually there are debug and release builds of a program; debug builds contain all the symbolic information for the debugger, and release builds are optimized to be fast and/or small. Sometimes you might want slightly different behavior from the debug version of the program. For example, you might have output statements that are for testing only. You might have assert()s, and you don't want to burden the release version with the extra code. In these cases, it is useful to exclude code from the compilation.

The #ifdef and #ifndef Directives

The #ifdef directive directs the preprocessor ...

Get C++ By Example: UnderC Learning 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.