What is pch.h and why is it needed to be included as the first header file?
pch stands for precompiled header.
In computer programming, a precompiled header is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler. Usage of precompiled headers may significantly reduce compilation time, especially when applied to large header files, header files that include many other header files, or header files that are included in many translation units.
To reduce compilation times, some compilers allow header files to be compiled into a form that is faster for the compiler to process. This intermediate form is known as a precompiled header, and is commonly held in a file named with the extension .pch or similar, such as .gch under the GNU Compiler Collection.
In Visual Studio, precompiled header is usually named "pch.h" (for console based applications), but it is possible to use different name, or not use it at all. Which file would be precompiled header, if any, is determined by projects settings.
If the precompiled header file is "pch.h" and the compile option is /Yu
, Visual Studio will not compile anything before the #include "pch.h"
in the source file; it assumes all code in the source up to and including that line is already compiled.
Precompiled headers C++ can't rename pch.h
Adjust the name of the precompiled header file in the Project Properties under Configuration Properties -> C/C++ -> Precompiled Headers.
Note that pch.cpp
has property to generate precompiled header.
Basically you may set the properties if and what precompiled header you use differently for each file in your project.
Related Topics
Is It Ok Not to Call the Destructor on Placement New Allocated Objects
Coding Practices Which Enable the Compiler/Optimizer to Make a Faster Program
Namespaces for Enum Types - Best Practices
Creating JSON Arrays in Boost Using Property Trees
Std::Pow Produce Different Result in 32 Bit and 64 Bit Application
C++11 Std::Threads VS Posix Threads
How Does a Sentinel Node Offer Benefits Over Null
Why Can't C++11 Move a Noncopyable Functor to a Std::Function
Why Can't I Use a "Break" Statement Inside a Ternary Conditional Statement in C++
Using Visual Studio Project Properties Effectively for Multiple Projects and Configurations
When a Float Variable Goes Out of the Float Limits, What Happens
Passing Constexpr Objects Around
How Should One Use Std::Optional
Adding Multiple Executables in Cmake
C/C++: Is This Undefined Behavior? (2D Arrays)
What Differences, If Any, Between C++03 and C++11 Can Be Detected at Run-Time