What exactly is precompiled headers? when are they used?
问题:
回答1:
Precompiled headers are an optimisation used during the compilation process.
Basically, if you compile something like stdio.h
with the exact same defines and environment, you can safely assume the result will be the same each time.
So the compiler remembers the "compiled" version of that header so it doesn't have to do it again.
In reality, it tends to be the initial group of headers that makes the difference so, if every one of your source files starts with:
#define XYZZY 42
#include <stdio.h>
#include <stdlib.h>
the first one compiles completely but remembers the state immediately following that third line. The next one can simply throw those three lines away totally and load up the saved state before continuing to compile the rest of the file.
The first time I saw this feature was on Windows with its massive windows.h
header file and, believe me, it made a lot of difference to overall build times.