In fact, in our life, a lot of things are like this, appear once two times, and often we ignore. Met many times, one day we noticed, and then want to get a clear. It may be noticed, but there is no need to get a clear heart. Someday it will confuse you and have to figure it out. No matter stdafx.h you notice, whether or not stdafx.h is confusing you, now let's get to the precompiled header.
What is a precompiled header
The precompiled header (precompiled header) is the program design when the head file is compiled into an intermediate format to save the overhead of the compiler repeatedly compiling the header file during development. --from "Wikipedia"
The meaning of the precompiled header is that it prevents a header file from being compiled repeatedly .
Why do I have precompiled headers
For example, some header files contain a huge amount of source code (such as Windows.h), if each CPP contains this header file, then it will cause the compilation process is very slow, because not only large, but also to be compiled several times. So, with the precompiled header technology. Extract a bunch of header files that almost all CPP contains, put them in one place, such as stdafx.h, and compile the project first, compiling the stdafx.cpp, then generate an intermediate file:. pch, files that all CPP can use. You can see if you have a. pch file in the debug/release of the directory where your project is located? This is the precompiled header after compilation. Maybe you've seen the. pch file, you don't know what it is, now do you understand? You look at the size of this file, more than 10M ~ one word: Gigantic! Should be the largest file in the project file.
features of precompiled files
But do you think that if the precompiled files are often modified, does it lose the pre-compiled meaning? So these precompiled files must be stable and not often modified.
use of precompiled headers
when creating a project, vs by default will be created: StdAfx.h and Stdafx.cpp. Then in the stdafx.h to add the various header files required for the project, and in Stdafx.cpp, as long as stdafx.h on it. When we compile, it will be compiled from Stdafx.cpp by default, generating a. pch file. When other CPP is compiled, the. pch file is loaded into memory, and of course the other CPP must include "stdafx.h". In fact, the. PCH contains all the code compilation results until the line "stdafx.h" is included, and we tend to place the # include "StdAfx.h" on the first line of the CPP. to Open the properties of CPP, you can see the following configuration:
You can try changing the configuration to see if the compilation time will be slow.
The AFX in Ps:stdafx represents the application Framework eXtensions. AFX is the old name of Microsoft Foundation Classes (MFC).
Finally, you are welcome to comment & Exchange, thank you.
C + + precompiled header file: stdafx.h