22.15. Preprocessor directives

Compiling a file is actually a multi-step process. Before actually compiling any code, a compiler uses something called a ‘preprocessor’ to look through the project files and carries out the instructions embodied in the various preprocessor directives. Any line of C++ that starts with # is a preprocessor directive. Some of them are #include, #define, #ifdef, #endif, and #pragma. Each preprocessor directive tells the compiler to do something before running. The instructions in the # directives are used to alter the contents of the file, which is only then passed on to the normal compilation process.

The #include directive

What the #include directive tells the compiler to do is to replace a line like #include “whatever.h” ...

Get Software Engineering and Computer Games 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.