在 C/C++ 中检测多余的#include? [英] Detecting superfluous #includes in C/C++?

查看:35
本文介绍了在 C/C++ 中检测多余的#include?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发现文件的标题部分一直在变大,但从未变小.在源文件的整个生命周期中,类可能已经移动和重构,并且很可能有很多 #includes 不再需要存在.将它们留在那里只会延长编译时间并添加不必要的编译依赖项.试图找出仍然需要哪些可能非常乏味.

I often find that the headers section of a file get larger and larger all the time but it never gets smaller. Throughout the life of a source file classes may have moved and been refactored and it's very possible that there are quite a few #includes that don't need to be there and anymore. Leaving them there only prolong the compile time and adds unnecessary compilation dependencies. Trying to figure out which are still needed can be quite tedious.

是否有某种工具可以检测多余的#include 指令并建议我可以安全删除哪些指令?
lint 可能会这样做吗?

Is there some kind of tool that can detect superfluous #include directives and suggest which ones I can safely remove?
Does lint do this maybe?

推荐答案

不是自动的,而是doxygen将为 #included 文件生成依赖关系图.您将不得不直观地浏览它们,但它们对于了解什么使用什么非常有用.

It's not automatic, but doxygen will produce dependency diagrams for #included files. You will have to go through them visually, but they can be very useful for getting a picture of what is using what.

这篇关于在 C/C++ 中检测多余的#include?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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