CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2000
    Posts
    3

    Talking 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.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449
    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

  3. #3
    Join Date
    Jun 1999
    Location
    San Diego, CA
    Posts
    600
    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
  •  





Click Here to Expand Forum to Full Width

Featured