 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chinmoy Mukherjee Guest
|
Posted: Fri Apr 29, 2005 9:11 am Post subject: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 12:18 pm Post subject: Re: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 12:26 pm Post subject: Re: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 3:01 pm Post subject: Re: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 3:06 pm Post subject: Re: Static checker for C++ |
|
|
[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
|
I guess the fact that you have #ifndef FILE_H /uses/ the macro.
--
Alvin
|
|
| Back to top |
|
 |
Jay Nabonne Guest
|
Posted: Fri Apr 29, 2005 4:09 pm Post subject: Re: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 4:13 pm Post subject: Re: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 4:27 pm Post subject: Re: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 4:34 pm Post subject: Re: Static checker for C++ |
|
|
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
|
Posted: Fri Apr 29, 2005 4:40 pm Post subject: Re: Static checker for C++ |
|
|
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 |
|
 |
|
|
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
|
|