Precompiled header
Precompiled header is a performance feature found in some C or C++ compilers used to reduce compilation time. The idea is to compile seldom changed header files into object code so that subsequent compilations are faster, at the cost of the initial, slower precompilation. Precompiled header files typically carry the .PCH file extension or .GCH extension (while using with gcc).
Advantages
The advantages of precompiled headers become more pronounced as the number of header files increases or as the amount of code in the header files become significantly large. This is the case with newer C++ code, such as the Boost library, which implements almost all of its code inside header files due to template constraints.
Usage
For example, suppose we have two C++ files:
// header.hpp ...
// source.cpp #include "header.hpp" ...
Now, if the precompiled header feature is turned on when compiling source.cpp for the first time, the compiler will generate header.pch. The next time source.cpp is compiled, the compiler can skip compiling header.hpp and more quickly use header.pch directly, instead, in the construction of source.cpp's output.
stdafx.h
stdafx.h is commonly used in Microsoft Windows projects as the name of a file which describes include files (both standard system include files and project specific include files) that are used frequently but are changed infrequently. Since many C/C++ source files for Windows programs include stdafx.h, making small changes in it means the entire project needs to be recompiled and small errors in it cause large errors in the rest of the project.
Compatible compilers (for example, Visual C++ 6.0 and newer) will precompile this file to reduce overall compile times. Visual C++ will also not compile anything before the #include "stdafx.h" in the source file, unless you uncheck the compile option /Yu'stdafx.h': it assumes all code in your source up to and including that line is already compiled.
The AFX in stdafx.h stands for Application Framework eXtensions. AFX was the original abbreviation for the Microsoft Foundation Classes (MFC). This type of file can also have alternate names, including "StdInclude.h".
GCC
Precompiled headers are supported in GCC (3.4 and newer).