Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "pch.h" and why is it needed to be included as the first header file?

#include "pch.h" #include <stdio.h> #include <string.h> 

What is "pch.h"? Why is it needed to be included as the first header file?

like image 870
Lee Tim Fu Avatar asked Jan 10 '19 04:01

Lee Tim Fu


People also ask

What is Stdafx h used for?

The file stdafx. h is usually used as a precompiled header file. Precompiled headers help to speed up compilation when a group of files in a project do not change.

How do you precompile a header?

The compiler options for precompiled headers are /Y . In the project property pages, the options are located under Configuration Properties > C/C++ > Precompiled Headers. You can choose to not use precompiled headers, and you can specify the header file name and the name and path of the output file.

Why we need header files at the top of each C++ program?

These preprocessor directives are used for instructing compiler that these files need to be processed before compilation. In C program should necessarily contain the header file which stands for standard input and output used to take input with the help of scanf() and printf() function respectively.

What is file extension PCH?

Contains programming code referenced by a source code file, often using an #include preprocessor directive; may reference other header (. H) files and other resources. PCH files are used by Microsoft Visual C++ and other software development programs, such as Apple Xcode.


1 Answers

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.

like image 105
P.W Avatar answered Sep 27 '22 22:09

P.W