问题描述
通常写新的$ C $当c你发现你缺少一个的#include,因为该文件不进行编译。够简单,您可以添加所需的#include。但后来不知何故你重构code,现在不再需要一对夫妇的#include指令。我如何发现哪些不再需要的吗?
Typically when writing new code you discover that you are missing a #include because the file doesn't compile. Simple enough, you add the required #include. But later you refactor the code somehow and now a couple of #include directives are no longer needed. How do I discover which ones are no longer needed?
当然,我可以手动删除部分或全部的#include行,并增加他们回来,直到文件再次编译,但这是不符合成千上万的文件大型项目确实可行的。是否有任何可用的工具,这将有助于自动化任务?
Of course I can manually remove some or all #include lines and add them back until the file compiles again, but this isn't really feasible in a large project with thousands of files. Are there any tools available that will help automating task?
推荐答案
您可以使用 PC - 皮棉/ FlexeLint 做到这一点。
You can use PC-Lint/FlexeLint to do that.
不同寻常的没有工具的一个免费版本的操作系统。
Unusually there isn't a free OS version of the tool available.
您可以通过引用传递,而不是按值传递和前瞻性声明中删除的#includes。这是因为编译器并不需要知道对象的在编译时的大小。这将需要大量的手工工作代表你不过。好事是它会降低你的编译时间。
You can remove #includes by passing by reference instead of passing by value and forward declaring. This is because the compiler doesn't need to know the size of the object at compile time. This will require a large amount of manual work on your behalf however. The good thing is it will reduce your compile times.
这篇关于我如何找到自动化未使用的#include指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!