Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Static checker for C++

10 views
Skip to first unread message

Chinmoy Mukherjee

unread,
Apr 29, 2005, 5:11:46 AM4/29/05
to
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

abece...@spambob.com

unread,
Apr 29, 2005, 8:18:28 AM4/29/05
to

Welcome to the club!
:-)

Alvin

unread,
Apr 29, 2005, 8:26:34 AM4/29/05
to
Chinmoy Mukherjee wrote:

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?

--
Alvin

abece...@spambob.com

unread,
Apr 29, 2005, 11:01:56 AM4/29/05
to
Alvin wrote:
> Chinmoy Mukherjee wrote:
>
> > 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 ?
>
> 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 ;-)

Alvin

unread,
Apr 29, 2005, 11:06:40 AM4/29/05
to
abece...@spambob.com wrote:

I guess the fact that you have #ifndef FILE_H /uses/ the macro.

--
Alvin

Jay Nabonne

unread,
Apr 29, 2005, 12:09:46 PM4/29/05
to

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

Victor Bazarov

unread,
Apr 29, 2005, 12:13:17 PM4/29/05
to

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

Jay Nabonne

unread,
Apr 29, 2005, 12:27:28 PM4/29/05
to
On Fri, 29 Apr 2005 12:13:17 -0400, Victor Bazarov wrote:

> Jay Nabonne wrote:
>> On Fri, 29 Apr 2005 14:41:46 +0530, Chinmoy Mukherjee wrote:
>>
>
> ... 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

Carl

unread,
Apr 29, 2005, 12:34:07 PM4/29/05
to
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


"Chinmoy Mukherjee" <a17...@motorola.com> wrote in message
news:4271FA52...@motorola.com...

Jay Nabonne

unread,
Apr 29, 2005, 12:40:23 PM4/29/05
to
On Fri, 29 Apr 2005 12:34:07 -0400, Carl wrote:

> 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

0 new messages