VC++ "Precompiled Header" project option

Started by
2 comments, last by demonkoryu 14 years ago
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 :)
Advertisement
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.
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?
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.

This topic is closed to new replies.

Advertisement