Precompiled Headers

What are precompiled headers? when are they used?

+7
source share
1 answer

Precompiled headers are the optimizations used in the compilation process.

Basically, if you compile something like stdio.h with exactly the same definitions and environment, you can safely assume that the result will be the same every time.

In this way, the compiler remembers the โ€œcompiledโ€ version of this header, so it does not need to do this again.

In fact, it tends to be the original header group, which makes a difference so if each of the source files starts with:

 #define XYZZY 42 #include <stdio.h> #include <stdlib.h> 

the first compiles completely, but remembers the state immediately after this third line. The next one may simply discard these three lines completely and load the saved state before continuing to compile the rest of the file.

For the first time I saw that this function was on Windows with a massive windows.h header file, and, believe me, this greatly influenced the overall build time.

+7
source

All Articles