Reputation: 1449
My understanding of precompiled headers is as follows:
We create the stdafx.h
file:
#pragma once
#include <code1.h>
#include <code2.h>
...
#include <codeN.h>
And the stdafx.cc
file:
#include <stdafx.h>
Now if each of the multiple main1.c
, main2.c
, main3.c
files include the stdafx.h
header, then when you compile the main1.c
for the first time, everything that the stdafx.h
includes will be parsed and compiled into an object file, but compiling the next main2.c
and main3.c
files will not require to parse the stdafx.h
file again.
However, suppose I only have a main1.c
file and no main2.c
or main3.c
files. Would using a precompiled header offer any improvements than just including codeX.h
into the main.c
directly?
Upvotes: 0
Views: 810
Reputation: 16089
It should be faster as the precompiled headers (should) already have been run through the pre-processor, compiler flags affecting the code here should also have done its things.
So compared to an include that still needs to do these things it should be faster.
Upvotes: 0
Reputation: 238311
Do precompiled headers speed up compilation if there is only one
.c
file that includes them?
Potentially yes, assuming you are using a previously pre-compiled header.
Upvotes: 2