Static checker for C++

C

Chinmoy Mukherjee

Hi Friends,

I want to find out whether my C++ code(set of files)
include some unused header files, do you know of any
free static checker in linux for the job ?

Regards,
Chinmoy
 
A

abecedarian

Chinmoy said:
Hi Friends,

I want to find out whether my C++ code(set of files)
include some unused header files, do you know of any
free static checker in linux for the job ?

Welcome to the club!
:)
 
A

Alvin

Chinmoy said:
Hi Friends,

I want to find out whether my C++ code(set of files)
include some unused header files, do you know of any
free static checker in linux for the job ?

Regards,
Chinmoy

From gcc manpage, what about the -Wunsed-macros. Apparently it gives a
warning for each unused macro. Not sure if this works for the inclusion
macros in the header files (#ifndef FILE_H #define FILE_H ... #endif). But
perhaps it will give some hints?
 
A

abecedarian

Alvin said:
From gcc manpage, what about the -Wunsed-macros. Apparently it gives a
warning for each unused macro. Not sure if this works for the inclusion
macros in the header files (#ifndef FILE_H #define FILE_H ... #endif). But
perhaps it will give some hints?

Think about your proposal again ;-)
 
J

Jay Nabonne

Hi Friends,

I want to find out whether my C++ code(set of files)
include some unused header files, do you know of any
free static checker in linux for the job ?

Regards,
Chinmoy

How about grep?

If the header file isn't being used, then it has not been #include'd
anywhere. Simply search for the name of the header file in your source.
The ones you don't find are not used.

- Jay
 
V

Victor Bazarov

Jay said:
How about grep?

If the header file isn't being used, then it has not been #include'd
anywhere. Simply search for the name of the header file in your source.
The ones you don't find are not used.

.... or you simply forgot that there is a subdirectory with source files
which actually might use them...

Besides, including a header doesn't necessarily constitute "using". What
if none of the constructs declared/defined in that header are ever used?

V
 
J

Jay Nabonne

... or you simply forgot that there is a subdirectory with source files
which actually might use them...

Well, grep -r :)
Besides, including a header doesn't necessarily constitute "using". What
if none of the constructs declared/defined in that header are ever used?

Yep. How the OP meant "using" was a little unclear. Other answers
went in the "nothing in the file is used" direction. I thought I'd throw
that option out, just in case that happened to be what the OP meant.

- Jay
 
C

Carl

for every cpp file
for every header include
comment out the include
compile the cpp file
if( compile_errors )
un-comment out the header
else
remove header include from cpp

this will work and its not that bad, because you can skip the header you
know are required and consentrate on the others.

I wonder if a compiler plugin could be run overnight to automate this
process, if one could be built
millions of compiling-hours a day could be saved by world-wide developers.
Carl
 
J

Jay Nabonne

for every cpp file
for every header include
comment out the include
compile the cpp file
if( compile_errors )
un-comment out the header
else
remove header include from cpp

This is how I have had to do it. There is one caveat though: if a header
file contains #defines that control compilation paths, the source file may
compile *error-free* without the header file included, but it may compile
*differently*. So the header file would still be needed to properly
configure the compile.

- Jay
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top