Automatic detection of "dead" headers?

D

Donovan Martin

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?
 
J

Jack Klein

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

A. W. Dunstan

Donovan said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top