c++ - 将通用文件包含在一个头文件中有什么好处?

标签 c++ c include precompiled-headers

我在查看 github 上的 doom3 代码时发现了一些不寻常的地方。几个文件只有一个包含一个名为 idlib/precompiled.h 的文件,这个文件包含几个其他头文件,如

...
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
#include <typeinfo>
#include <errno.h>
#include <math.h>
...

和程序头

#include "../framework/BuildVersion.h"
#include "../framework/BuildDefines.h"
#include "../framework/Licensee.h"
#include "../framework/CmdSystem.h"
#include "../framework/CVarSystem.h"

我想知道是否有什么好的理由,因为这是我第一次看到这样的东西

最佳答案

这称为预编译 header 。主要好处是大大提高了编译速度。

precompiled.h 中的所有头文件每个项目只编​​译一次。如果没有预编译头文件,每个头文件内容将被编译多次:对于包含它的每个 .cpp 文件。

关于c++ - 将通用文件包含在一个头文件中有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8431041/

相关文章:

c++ - 使用 getLine 在 C++ 中读取 CSV 文件中的分隔列

ruby - Perl:如何模拟 Ruby 的 "include/extend"机制?

c# - 指定的包含路径无效

c++ - VS2013 上 Windows 上的全局包含路径

c++ - 如何使用 SHChangeNotify 通知文件夹

c++ - 如何删除std::vector中选定的随机数据?

c++ - 在std::qsort的compare函数中处理错误情况

c - udp套接字到底接收什么?

c++ - 在一次操作中进行多个矩阵-矩阵乘法

c - 纯 C 中的异常处理库