简体   繁体   English

C ++未使用的头文件

[英]C++ unused headers

I would like to remove some unused headers from the large codebase. 我想从大型代码库中删除一些未使用的标头。 I know that there are some open-source tools but number of false positives is too big. 我知道有一些开源工具,但误报的数量太大。 The idea was to run script for each file. 想法是为每个文件运行脚本。 Consequently, remove include, tries to compile, if compile goes to next line (with include removed), otherwise leave include and go to the next line. 因此,如果编译转到下一行(删除了包含),则删除包含并尝试编译(否则删除包含),否则离开包含并转到下一行。

Is there any problems connected with this idea, looking in the long-term? 长期来看,与这个想法有关的任何问题吗? Or is there any easier option to try? 还是有更容易尝试的选择?

Is there any problems connected with this idea 这个想法有什么问题吗

Yes. 是。 A file can compile successfully even if it has missing include files, so this can have false positives, and may remove headers that are actually used. 即使缺少包含文件,文件也可以成功编译,因此可能会有误报,并且可能会删除实际使用的标头。

It is quite a difficult task to analyse which headers should be included, and which are unnecessary, both manually and automatically. 手动和自动分析哪些标头应包括在内,哪些标头是不必要的,是一项艰巨的任务。 Tools have been made to do the checking automatically. 已经制作了可以自动进行检查的工具。 Even if "number of false positives is too big ", it's still (in my experience) a small fraction of all included headers, so it is far less work to check results of such tool than compare includes of every file to the entire content of those files. 即使“误报的数量过大 ”,(以我的经验)仍然只是所有包含的标头的一小部分,因此,检查这种工具的结果要比将每个文件的包含内容与整个文件的全部内容进行比较相比要少得多。这些文件。 Even the script that you suggest can be better than nothing, as long as you don't remove the includes without manual checking. 只要您不手工检查就不要删除包含内容,即使您建议的脚本也总比没有好。

It helps manual checking to make the files as small as possible. 它有助于手动检查以使文件尽可能小。 As a side-effect, this also makes incremental compilation much faster (but compilation form scratch slower). 副作用是,这也使增量编译更快(但从头开始的编译速度较慢)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM