Automatic detection of "dead" headers?

Discussion in 'C++' started by Donovan Martin, Oct 6, 2004.

  1. Detecting dead headers is an extremely tiresome and lengthy process. Is
    there an automated utility available which might do this for me? That is,
    some utility that will check my .cpp and .h files and determine which
    headers that are referenced are unnecessary?
     
    Donovan Martin, Oct 6, 2004
    #1
    1. Advertising

  2. Donovan Martin

    Jack Klein Guest

    On Tue, 5 Oct 2004 23:17:49 -0400, "Donovan Martin"
    <> wrote in comp.lang.c++:

    > Detecting dead headers is an extremely tiresome and lengthy process. Is
    > there an automated utility available which might do this for me? That is,
    > some utility that will check my .cpp and .h files and determine which
    > headers that are referenced are unnecessary?


    Commercial product PC Lint, http://www.gimpel.org. And it does much
    more. Worth many times its price.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Oct 6, 2004
    #2
    1. Advertising

  3. E. Robert Tisdale, Oct 6, 2004
    #3
  4. Donovan Martin wrote:

    > Detecting dead headers is an extremely tiresome and lengthy process. Is
    > there an automated utility available which might do this for me? That is,
    > some utility that will check my .cpp and .h files and determine which
    > headers that are referenced are unnecessary?


    I wrote a shell script several years ago to do that. It's far from perfect,
    but it's a start (and free). It searches for the name of the included file
    in the file doing the including. If the nameis found more than once I
    assume the include needs to be there.


    #!/bin/tcsh
    set tmpfil=un.inc.$$
    foreach f ( $* )
    # See what file f "includes" (ignore <includes> - those are usually
    # system things).
    grep '^#include' $f | cut -f2 -d'"' | grep -v include | cut -f1 -d. >
    $tmpfil
    set firstPass=0

    #
    # For each file thus included...
    #
    foreach i (`cat $tmpfil`)
    # If the name included appears more than once in the file
    # being checked...
    expr `grep $i $f | wc -l` \> 1 > /dev/null
    if ( $status == "1" ) then
    # Print the filename the 1st time we find a possibly useless include.
    if ( `expr $firstPass == 0` ) then
    set firstPass=1
    echo $f
    endif
    # Print the name of the included file.
    echo "\t" $i
    endif
    end
    end
    rm $tmpfil
     
    A. W. Dunstan, Oct 6, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dont bother
    Replies:
    0
    Views:
    868
    dont bother
    Mar 3, 2004
  2. Phil
    Replies:
    4
    Views:
    734
    Gabriel Genellina
    Jan 17, 2010
  3. Ian
    Replies:
    2
    Views:
    2,113
  4. balcer

    Dead gateway detection

    balcer, Jun 23, 2005, in forum: Ruby
    Replies:
    6
    Views:
    208
    balcer
    Jun 24, 2005
  5. Replies:
    2
    Views:
    531
Loading...

Share This Page