简体   繁体   English

什么是“pch.h”,为什么需要将它作为第一个 header 文件包含在内?

[英]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"?什么是“pch.h”? Why is it needed to be included as the first header file?为什么需要将它作为第一个 header 文件包含在内?

pch stands for precompiled header . pch代表预编译头文件

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.在计算机编程中,预编译头文件是一个(C 或 C++)头文件,它被编译成一种中间形式,以便编译器更快地处理。 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.这种中间形式称为预编译头文件,通常保存在一个以 .pch 或类似扩展名命名的文件中,例如 GNU Compiler Collection 下的 .gch。

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.在 Visual Studio 中,预编译头通常命名为“pch.h”(对于基于控制台的应用程序),但可以使用不同的名称,或者根本不使用它。 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;如果预编译的头文件是 "pch.h" 并且编译选项是/Yu ,Visual Studio 将不会编译源文件中#include "pch.h"之前的任何内容; it assumes all code in the source up to and including that line is already compiled.它假定源代码中直到并包括该行的所有代码都已编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM