预编译标头是递归的

Are precompiled headers recursive?

本文关键字:递归 编译      更新时间:2023-10-16

让我们假设我的.h文件用于创建预编译头文件如下所示:

stdafx.h

#include "A.h" //an external library

.. 和 "A.h" 包括一堆其他标头:

#include "B.h" //other headers from an external library included by "A.h"
#include "C.h"
//...
是否也会为"B.h"

和"C.h"生成预编译头(以及这两个文件包含的头文件,等等...),或者我是否也必须在我的"stdafx.h"中包含"B.h"和"C.h"?

是的,预编译状态将包括 B 和 C。

预编译的工作原理是运行编译器直到 stdafx.h 的末尾并将其状态转储到磁盘,然后在编译每个源文件的正文之前恢复该状态。 编译器在编译 stdafx.h 时看到的所有内容都会进入该状态。

(换句话说:编译 stdafx.h 的过程完全相同,无论您是生成预编译状态还是只是"正常"编译源文件 - 只是在预编译情况下编译器在文件末尾停止。 即使它愿意,它也不能区别对待B和C。