有没有理由不应该在.pch文件中添加所有导入? [英] Is there a reason for which one should not add all the imports inside .pch file?

查看:97
本文介绍了有没有理由不应该在.pch文件中添加所有导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要是引用应用程序级别的导入,而不是在构建库时,在这种情况下很明显为什么要避免在.pch文件中导入标题。

I'm mainly refering to application-level imports, not when you build a library, in which case is obvious why you should avoid importing the headers inside the .pch file.

推荐答案

.pch 文件的要点是它可以预先编译一次并保持不变。

The point of the .pch file is that it can be precompiled once and left alone.

如果您在 .pch 中导入所有应用程序标头,则每次更改其中任何一个标头时都必须重新编译它,否定所有的好处。更糟糕的是,这最终意味着必须重建项目中的每个其他文件,因为 .pch 的内容已更改。

If you import all of your application headers in the .pch, it has to be recompiled every time you change any one of those headers, negating all of the benefits. Worse yet, this ends up meaning that every other file in your project has to be rebuilt, because the contents of the .pch changed.

你的 .pch 应该引入的唯一标题是几乎永远不会改变的标题,比如系统标题。

The only headers that should be pulled in by your .pch are headers that'll almost never change, like system headers.

这篇关于有没有理由不应该在.pch文件中添加所有导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆