Code Cleanup Tool

F

Frank Neuhaus

Hi
sorry - I guess this is slightly OT but still ;)

Iam looking for some tool (win32 please) that can find unused member
functions / member variables in my project. Does anyone have any suggestions
there? Google didnt help me much :/

Thanks in advance
 
G

Gernot Frisch

Frank Neuhaus said:
Hi
sorry - I guess this is slightly OT but still ;)

Iam looking for some tool (win32 please) that can find unused member
functions / member variables in my project. Does anyone have any
suggestions there? Google didnt help me much :/

Visual Studio >=7.0 with warning level set to "scream-at-me(tm)(c)(R)"
 
F

Frank Neuhaus

Visual Studio >=7.0 with warning level set to "scream-at-me(tm)(c)(R)"

Thanks for your reply. I just tried that. It already helped a bit - it
reports unreachable code inside functions, unused parameters and unused
global functions. But unfortunately it doesnt report unused member
functions/variables :(
 
G

Gernot Frisch

Thanks for your reply. I just tried that. It already helped a bit -
it reports unreachable code inside functions, unused parameters and
unused global functions. But unfortunately it doesnt report unused
member functions/variables :(

unused variables should be listed:

void foo()
{
int a;
int b=0;
}

warning C4101: 'a' : unreferenced local variable
warning C4189: 'b' : local variable is initialized but not referenced

for unused functions - the linker will usually get rid of them. No, I
don't know any tool that can list this for you, because only the
linker knows what functions are used.
 
F

Frank Neuhaus

unused variables should be listed:
void foo()
{
int a;
int b=0;
}

warning C4101: 'a' : unreferenced local variable
warning C4189: 'b' : local variable is initialized but not referenced

for unused functions - the linker will usually get rid of them. No, I
don't know any tool that can list this for you, because only the linker
knows what functions are used.

I meant member variables - anyway... I know its not relevant for the actual
compiler, but Id like to clean up my code and its kinda hard to do it
manually as the code is too big to instantly know which function is used,
which one is deprecated etc...

So if anyone else has suggestions -...
 
D

David

Hello Frank,

Thanks for your reply. I just tried that. It already helped a bit - it
reports unreachable code inside functions, unused parameters and unused
global functions. But unfortunately it doesnt report unused member
functions/variables :(

You might also try one of the "lint for C++" or static analysis tools
(Klockwork 7?). In general, unused variables and methods in classes
would be very hard to suggest that they weren't used. The linker
could perform such a step if there wasn't a chance that the code/vars
wouldn't be found by other means. Classes do much more than just
group together values and functions that may be unused.

Classes are abstractions of objects that your application may use.
The fact that you don't make use of a particular method doesn't
necessarily mean that it should be removed. You might be planning
on using that component later. The class is a building block for
others to build on. Hopefully the abstraction was valid.

Static analysis tools can find such items to remove. These tools
aren't cheap though. I've not read why you want to remove the
unused components from your code.

I generally review my legacy classes as I work with them to
understand if the abstractions are valid. There are times that
they get rewritten. Certainly if you think a method or value
isn't used -- comment it out, compile, link, and look for the
errors. With less common value/method names you might be able
to get away with a search on the source code.

David
 
C

Christian Gollwitzer

Frank said:
Iam looking for some tool (win32 please) that can find unused member
functions / member variables in my project. Does anyone have any suggestions
there? Google didnt help me much :/

You could try running doxygen over the whole project. If you enable the
"source code browser", it writes a "referenced by..." entry to all
function/member descriptions. You could maybe even tweak it (its
opensource) to output every unreferenced function/member to stderr.

However, beware that virtual member functions are not referenced in this
sense, since this is a static analysis.

Christian
 

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,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top