Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precompiled headers

What exactly is precompiled headers? when are they used?

like image 458
lital maatuk Avatar asked Feb 10 '11 06:02

lital maatuk


People also ask

Which header file automatically include in source code?

The C compiler automatically adds the C library (usually -lc ) to the linking command.

What is #include Stdafx h in C++?

#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.


Video Answer


1 Answers

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.

like image 51
paxdiablo Avatar answered Dec 17 '22 06:12

paxdiablo