C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Static checker for C++

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Chinmoy Mukherjee
Guest





PostPosted: Fri Apr 29, 2005 9:11 am    Post subject: Static checker for C++ Reply with quote



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

Back to top
abecedarian@spambob.com
Guest





PostPosted: Fri Apr 29, 2005 12:18 pm    Post subject: Re: Static checker for C++ Reply with quote



Chinmoy Mukherjee wrote:
Quote:
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!
:-)


Back to top
Alvin
Guest





PostPosted: Fri Apr 29, 2005 12:26 pm    Post subject: Re: Static checker for C++ Reply with quote



Chinmoy Mukherjee wrote:

Quote:
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?

--
Alvin

Back to top
abecedarian@spambob.com
Guest





PostPosted: Fri Apr 29, 2005 3:01 pm    Post subject: Re: Static checker for C++ Reply with quote

Alvin wrote:
Quote:
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 ;-)


Back to top
Alvin
Guest





PostPosted: Fri Apr 29, 2005 3:06 pm    Post subject: Re: Static checker for C++ Reply with quote

[email]abecedarian (AT) spambob (DOT) com[/email] wrote:

Quote:
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 Wink

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

--
Alvin

Back to top
Jay Nabonne
Guest





PostPosted: Fri Apr 29, 2005 4:09 pm    Post subject: Re: Static checker for C++ Reply with quote

On Fri, 29 Apr 2005 14:41:46 +0530, Chinmoy Mukherjee wrote:

Quote:
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

Back to top
Victor Bazarov
Guest





PostPosted: Fri Apr 29, 2005 4:13 pm    Post subject: Re: Static checker for C++ Reply with quote

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

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.

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

Back to top
Jay Nabonne
Guest





PostPosted: Fri Apr 29, 2005 4:27 pm    Post subject: Re: Static checker for C++ Reply with quote

On Fri, 29 Apr 2005 12:13:17 -0400, Victor Bazarov wrote:

Quote:
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 :)

Quote:

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

Back to top
Carl
Guest





PostPosted: Fri Apr 29, 2005 4:34 pm    Post subject: Re: Static checker for C++ Reply with quote

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" <a17199 (AT) motorola (DOT) com> wrote

Quote:
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




Back to top
Jay Nabonne
Guest





PostPosted: Fri Apr 29, 2005 4:40 pm    Post subject: Re: Static checker for C++ Reply with quote

On Fri, 29 Apr 2005 12:34:07 -0400, Carl wrote:

Quote:
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


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.