What exactly is precompiled headers? when are they used?
The C compiler automatically adds the C library (usually -lc ) to the linking command.
#include "stdafx.h" The file stdafx. h is usually used as a precompiled header file. Precompiled headers help to speed up compilation when a group of files in a project do not change.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With