gpt4 book ai didi

C++ 模块 : module implementation units for unnecessary recompilation?

转载 作者:搜寻专家 更新时间:2023-10-31 02:07:41 25 4
gpt4 key购买 nike

最近观看的 CppCon 2017 视频:Boris Kolpackov“构建 C++ 模块” https://www.youtube.com/watch?v=E8EbDcLQAoc

大约在 31:35,他开始解释说我们仍然应该使用 header /源代码拆分,并给出了 3 个原因。第一个原因:

如果您在触摸此模块时在同一位置同时声明/定义,则所有其他依赖于模块接口(interface) (BMI) 的模块都将被重新编译。

而且我一点也不喜欢。听起来我们还处于 90 年代,编译器还不够聪明,看不出 BMI 相关更改和实现相关更改之间的差异。正如我所见,编译器能够快速扫描每个模块并从中仅生成 BMI。如果 BMI 没有改变——不要重新编译依赖它的其他模块。

还是我遗漏了什么?

最佳答案

那次谈话的作者后来说重新编译问题是一个实现问题。引用文章Common C++ Modules TS Misconceptions鲍里斯·科尔帕科夫:

It turns out a lot of people would like to get rid of the header/source split (or, in modules terms, interface/implementation split) and keep everything in a single file. You can do that in Modules TS: with modules (unlike headers) you can define non-inline functions and variables in module interface units. So if you want to keep everything in a single file, you can.

Now, keeping everything in a single file may have negative build performance implications but it appears a smart enough build system in cooperation with the compiler should be able to overcome this. See this discussion for details.

引用 Gor Nishanov (Coroutines TS 的项目编辑器)来自链接线程:

That is up to you how to structure your code. Module TS does not impose on you how you decompose your module into individual files. If you want, you can implement your entire module in the interface file (thus you will have C# like experience), or you can partition your module into an interface and one or more implementation files.

Modules TS的项目编辑, 加布里埃尔·多斯雷斯, commented on the MSVC implementation :

Ideally, only semantics-relevant changes should trigger recompilation keyed on the IFC.

(作为旁注,模块 TS has now been approved 并发送给 ISO 进行发布。)

关于C++ 模块 : module implementation units for unnecessary recompilation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48306676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com