Sign in to follow this  
PrestoChung

VC++ "Precompiled Header" project option

Recommended Posts

PrestoChung    334
Hi when I create a new project in Microsoft VC9 it gives me the option for "Precompiled header". The first few results I searched through didn't really explain what this actually does. I got the impression that it might speed up 'build times' (which bring up another question, what is the difference between 'compiling' and 'building'?) I noticed that my exe size with the same source files was 50kb when i created a new project with precompiled header, vs my other project was 46kb which may or may not have had this option. could this be the result of not having precompiled headers? Thanks :)

Share this post


Link to post
Share on other sites
demonkoryu    980
Precompiled headers don't add to your .exe size.

They are just what the name says: a bunch of header files that are precompiled and stored for later compile cycles. Since these headers are made of a huge bunch of code, and generally included in every source (.c/.cpp) file, this can speed up compile times considerably.

The file "stdafx.h" is by convention (unless you configure another precompiled header file in VC++) used for this purpose. You #include your most used header files in that file and then #include "stdafx.h" in every of your source files.

Share this post


Link to post
Share on other sites
PrestoChung    334
Thanks for the reply.
It pre-compiles just my headers? if i create a header file in my project called stdafx.h, that will be precompiled even if i don't choose the precompile option then?

My project right now has two other source & header file besides main.cpp.

Is only main intended to have all the headers? I have found it necessary to have one of the headers included in the other one. would stdafx.h be a way to easily do this for all headers?

Share this post


Link to post
Share on other sites
demonkoryu    980
Quote:
Original post by PrestoChung
Thanks for the reply.
It pre-compiles just my headers? if i create a header file in my project called stdafx.h, that will be precompiled even if i don't choose the precompile option then?

No, but when you activate PCH it will conventionally be used.
Quote:

My project right now has two other source & header file besides main.cpp.

Is only main intended to have all the headers? I have found it necessary to have one of the headers included in the other one. would stdafx.h be a way to easily do this for all headers?


No, it's more used to cut down on compile times for huge library headers like <cstdlib> or <iostream>, since these take a great deal of time to compile (they are large and in addition pull in other library headers and so on). And boost stuff, of course. Boost headers take aeons to compile.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this