开发者

Can I tell GCC to fail if I include header files unnecessarily?

开发者 https://www.devze.com 2023-01-29 04:47 出处:网络
The project I\'m working on recently made a big effort to cleanup the code by turning on all the strictest GCC warnings and iterating until it compiled.Now, for instance, compilation fails if I declar

The project I'm working on recently made a big effort to cleanup the code by turning on all the strictest GCC warnings and iterating until it compiled. Now, for instance, compilation fails if I declare a variable and don't use it.

After my latest development task there I see that there is a header file included somewhere that is now unnecessary. Is there any good way to find开发者_JAVA百科 other such header files (and in such a way reduce dependencies) other than trying to remove a header file and seeing if anything breaks?

I am using GCC 4.3.2 on Linux.


No, there's no way to get gcc to fail if a header isn't required. Included headers can contain pretty much anything, so it is assumed that whoever included them had good reason to do so. Imagine the following somewhat pathological case:

int some_function(int x) {
#include "function_body.h"
return x;
}

It's certainly not good form, but it would still compile if you removed the include. So, an automatic checker might declare it "unnecessary," even though the behavior is presumably different when the function body is actually there.

0

精彩评论

暂无评论...
验证码 换一张
取 消