|
-
July 3rd, 2002, 11:26 AM
#1
Get rid of #include that is not used
Most often during development, we "#include" something that is not use later on. However, these "#include" statements are still somewhere in the source files.
For instance, I include #include "Apple.h" because I need Apple class, but later decide not to use Apple in my source. Now that include statement is hanging somewhere in the source which I should be get rid of. Because it creates dependency during compilation.
Is there an easy way to detect which #include statement that is not being used?
Thanks.
-
July 3rd, 2002, 11:44 AM
#2
It's not really that easy to do, unless your compiler has an option to detect unused #include files.
I know that the PC-LINT program from www.gimple.com can detect unused #include files. Maybe there are other utilities out there that can do this. But trying to do this by hand, like I said, is not easy, and most likely error-prone.
Regards,
Paul McKenzie
-
July 3rd, 2002, 03:50 PM
#3
It's not really that hard to do, unless you have hundreds of include files. Just comment out your #include statements one by one, working from the bottom upwards, and try to see if it compiles. If it can compile without a problem, the commented out include is not needed.
Except you have to watch out for those include files that provides #define's that are compilation directives, for example
#define USE_WIN32
or something like that. Removing such include file may not cause any compilation problem, but will cause the wrong code to be compiled.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|