C / C ++:检测多余#includes? [英] C/C++: Detecting superfluous #includes?

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

问题描述

我经常发现文件的标题部分越来越大,但是它从不变小。在源文件的整个生命周期中,类可能已被移动并被重构,并且很可能存在不少于 #includes 的不太可能。离开它们只能延长编译时间并增加不必要的编译依赖关系。试图找出仍然需要的可能是相当乏味的。



有没有什么工具可以检测多余的#include指令,并建议我可以安全地删除哪些?

这可能吗?

解决方案

这不是自动的,而是 Doxygen 将为#included文件生成依赖关系图。你必须通过视觉来看待他们,但是他们可以非常有用的了解什么是使用什么。


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.

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?

解决方案

It's not automatic, but Doxygen will produce dependancy 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 ++:检测多余#includes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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