Connecting Tech Pros Worldwide Forums | Help | Site Map

Automatic detection of "dead" headers?

Donovan Martin
Guest
 
Posts: n/a
#1: Jul 22 '05
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?



Jack Klein
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Automatic detection of "dead" headers?


On Tue, 5 Oct 2004 23:17:49 -0400, "Donovan Martin"
<nospam@nospam.spam> wrote in comp.lang.c++:
[color=blue]
> 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?[/color]

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/~a...FAQ-acllc.html
E. Robert Tisdale
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Automatic detection of "dead" headers?


Jack Klein wrote:
[color=blue]
> Commercial product PC Lint, http://www.gimpel.org.
> And it does much more. Worth many times its price.[/color]

Are you sure that you didn't mean

http://www.gimpel.com/
A. W. Dunstan
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Automatic detection of "dead" headers?


Donovan Martin wrote:
[color=blue]
> 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?[/color]

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




Closed Thread