自动从C源中删除未使用的#includes? [英] automatically remove unused #includes from C source?

查看:39
本文介绍了自动从C源中删除未使用的#includes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


有没有人知道可以自动分析C源的工具

删除未使用的#includes?


谢谢,

Sean

Hi All,

Does anyone know of a tool that can automatically analyze C source to
remove unused #includes?

Thanks,
Sean

推荐答案

文章< 11 *** ******************@k70g2000cwa.googlegroups。 com>,

< sm ********* @ gmail.comwrote:
In article <11*********************@k70g2000cwa.googlegroups. com>,
<sm*********@gmail.comwrote:

>有没有人知道一个可以自动分析C源的工具,以便删除未使用的#includes?
>Does anyone know of a tool that can automatically analyze C source to
remove unused #includes?



整蛊。


include1.h中的#define可能用于include2.h中的#define <可以使用
来构建include3.h中的类型,这可能是由include5.h引入的

函数声明所需要的。 />
include4.h,函数名称可能是伪装数组

include6.h中的初始化表单,分析器必须分析你的
来看看你是否直接引用那个函数

或者你是否使用数组初始化......


换句话说,这样的工具必须要几乎是一个C编译器

本身,但是一个跟踪所有影响的东西。用来建立每个令牌的
,并找出了什么后都没用过。


开始评论可能更容易#include''s和

看看是否出现任何编译问题。

-

如果你撒谎到编译器,它会得到报复。 - Henry Spencer

Tricky.

A #define in include1.h might be used in a #define in include2.h that
might be used to build a type in include3.h that might be needed by a
function declaration brought in by include5.h that is #include''d by
include4.h, and the function name might be in a disguised array
initialization form in include6.h and the analyzer would have to
analyze your source to see whether you refer to that function directly
or if you use the array initialization...

In other words, such a tool would have to pretty much be a C compiler
itself, but one that kept track of all the "influences" that went
to build up every token, and figured out what wasn''t used after-all.

It might be easier just to start commenting out #include''s and
seeing if any compile problems came up.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer


2006年10月20日星期五17:39:25 +0000(UTC),Walter Roberson写道:
On Fri, 20 Oct 2006 17:39:25 +0000 (UTC), Walter Roberson wrote:

< sm ********* @ gmail.comwrote:
<sm*********@gmail.comwrote:

>>有没有人知道一个工具可以自动分析C源来删除未使用的#includes?
>>Does anyone know of a tool that can automatically analyze C source to
remove unused #includes?


开始评论#include'和
可能更容易看到是否出现任何编译问题。


It might be easier just to start commenting out #include''s and
seeing if any compile problems came up.



自动化,你有所需的工具!


祝福,

Roland Pibinger

Automate that and you have the requested tool!

Best wishes,
Roland Pibinger


文章< 45 ************** @ news.utanet.at>,

Roland Pibinger< rp ***** @ yahoo.comwrote:
In article <45**************@news.utanet.at>,
Roland Pibinger <rp*****@yahoo.comwrote:

>星期五,2006年10月20日17:39:25 +0000(UTC), Walter Roberson写道:
>On Fri, 20 Oct 2006 17:39:25 +0000 (UTC), Walter Roberson wrote:

>< sm ********* @ gmail.comwrote:
><sm*********@gmail.comwrote:

>>>有没有人知道可以自动分析C源的工具来移除未使用的#includes?
>>>Does anyone know of a tool that can automatically analyze C source to
remove unused #includes?


>>开始评论可能更容易#包括'和'
看看是否出现任何编译问题。
>>It might be easier just to start commenting out #include''s and
seeing if any compile problems came up.


>自动执行该操作并获得所需的工具!
>Automate that and you have the requested tool!



包括一个特定的文件最终可能会更改

的含义,但代码可能会在没有它的情况下正常编译。


例如,你可能有一个包含

的包含文件
#define _use_search_heuristics 1


然后代码可能有


#if定义(_use_search_heuristics)

/ *单向执行* /

#else

/ *用不同的方式做* /

#endif


代码无论哪种方式都有效。


因此,为了通过检查编译结果来测试是否需要任何特定的#include确实需要
,你需要分析

编译对象,strip输出符号表和调试信息以及

编译时间戳等,并比较生成的代码。

-

有一些想法所以错误的是,只有一个非常聪明的人才能相信他们。 - George Orwell

including a particular file can end up changing the meaning of
something else, but the code might compile fine without it.

For example, you might have an include file that contained

#define _use_search_heuristics 1

Then the code might have

#if defined(_use_search_heuristics)
/* do it one way */
#else
/* do it a different way */
#endif

where the code is valid either way.

Thus in order to test whether any particular #include is really
needed by checking the compile results, you need to analyze the
compiled object, strip out symbol tables and debug information and
compile timestamps and so on, and compare the generated code.
--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell


这篇关于自动从C源中删除未使用的#includes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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