Tool to certify Includes are necessary

Started by
6 comments, last by Colin Jeanne 18 years, 8 months ago
Didn't know exactly where to put this... Is there a tool that will read up your code and: 1) Create a list of unused variables (I know VS already does this in the form of a warning) 2) Create a list of unnecessary #includes, source code that #includes other files, but that #include is not necessary... What other code-cleaning tools do you guys use?
Advertisement
For #2 I'm very high-tech about it. My methodology consists of:

"WTF is this being included for?"
Comment it out.
Try to compile.
-Mike
^^^ Hehe, it's the only way I know how to do it.
I've heard that PCLint is supposed to be able to do that but I don't know for sure.

Game Programming Blog: www.mattnewport.com/blog

You forgot some steps Anon Mike:

"WTF is this being included for?"
Comment out #include<MyClass>.
Try to compile.
Doesn't compile
Add in header "class MyClass";
Try to compile again.
I think it's important to include everything that is directly required by a header or source file - you shouldn't depend on a particular header to include another that you also need, unless you're sure that your program structure isn't going to change in the future.

If you use a windows type (HWND, WPARAM etc) anywhere in the file, include windows.h (unless the source file's header includes it). If you're using MyClass, include MyClass.h.

Removing headers just because your program would still compile afterwards is a step towards losing your sanity.
I know that for java, a tool like this exists for NetBeans and its great, but unfortunately, I don't know of an equivalent for c++. Would make life easier though, wouldn't it?
Quote:Original post by Wavarian
I think it's important to include everything that is directly required by a header or source file - you shouldn't depend on a particular header to include another that you also need, unless you're sure that your program structure isn't going to change in the future.

If you use a windows type (HWND, WPARAM etc) anywhere in the file, include windows.h (unless the source file's header includes it). If you're using MyClass, include MyClass.h.

Removing headers just because your program would still compile afterwards is a step towards losing your sanity.

I agree. This is how I handle #includes.

This topic is closed to new replies.

Advertisement