关于 Visual C 中预编译头的问题

发布于 2024-08-02 23:21:26 字数 373 浏览 8 评论 0原文

如果我将一个标头 (ah) 放入 stdafx.h 中,并且该标头包含 stdafx.h 中未提及的另一个标头 (bh),则每次有人包含 ah 时都会访问 bh 还是将其编译为 ah 的一部分?如果编译成ah,有人直接include bh会怎样?这会预编译吗?

我问这个问题的动机是我试图优化我所使用的软件的 stdafx.h 文件的内容。重建和增量构建时间对我们都很重要。我想知道是否可以简单地搜索所有 .cpp 文件中的 #include 指令并计算每个文件被包含的次数。经常包含的文件可能是 stdafx.h 文件的良好候选者。当然,如果我不仅要考虑包含哪些文件,还要考虑包含的文件包含哪些文件,那么这种策略完全是假的。

我怀疑这是否重要,但我们使用的是 Visual Studio 2005。

If I put a header (a.h) into stdafx.h and that header includes another header (b.h) that is not mentioned in stdafx.h, will b.h be visited every time someone includes a.h or is it compiled in as part of a.h? If it is compiled into a.h, what happens when someone includes b.h directly? Will this be precompiled or not?

My motivation for asking this question is that I am trying to optimize the content of the stdafx.h files for the software that I work on. Both rebuild and incremental build times are important to us. I was wondering whether I could simply search through all of the .cpp files for #include directives and count the number of times each file is included. Files which were included often might be good candidates for the stdafx.h file. Of course, this strategy is completely bogus if I have to consider not only which files are included, but also which files the included files include.

I doubt it matters, but we are using Visual Studio 2005.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2024-08-09 23:21:26

ah和bh将成为预编译头的一部分,以后不需要包含它们。您所需要的只是在需要 ah 或 bh 的地方包含 stdafx.h 。如果您在 stdafx.h 之后显式包含 ah 或 bh (stdafx.h 包含之前的所有代码都将被忽略),那么它将不会被第二次编译(只是因为它们通常受 #pragma Once 保护) code> 指令或定义),但是如果您询问的话,编译器会在硬盘上打开该文件,

顺便说一句,您应该知道,您可以使用多个预编译头文件(但每个 cpp 文件中不超过一个) 。

a.h and b.h will be part of precompiled header, and there is no need to include them later. All you need is to include stdafx.h where a.h or b.h are required. If you'll include a.h or b.h explicitly after stdafx.h (all code before stdafx.h include are ignored), then it'll not be compiled second time (just because they are usually protected by #pragma once directive or defines), but compiler will open that file on hard disk if you are asking about it,

By the way, you should know, that you could use several precompiled header files (but no more than one in every cpp file).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文