Sign in to follow this  
Ksingh30

unused method

Recommended Posts

Ksingh30    100
Is there some kind of tool that can let me do the following. I have a fairly large C++ app I am working on. and theres lots of methods in there that I think are never invoked. is there a tool that can go through my code and tell me which methods never get called?

Share this post


Link to post
Share on other sites
Palidine    1315
IIRC an optimizing compiler will just strip that all out for you (if you're worried about EXE size). If it's just about keeping the code clean, I'm sure one exists but don't know it off the top of my head.

If you want to go the DIY route, there are plenty of pretty awesome lexing/parsing libraries out there that you could use to write such a tool.

-me

Share this post


Link to post
Share on other sites
Antheus    2409
No there isn't. C++ isn't required to keep unused methods. Furthermore, many methods get inlined, meaning that they'll be missing from the executable in their source form.

One way that might work would be DoxyGen.

Share this post


Link to post
Share on other sites
Rydinare    487
Quote:
Original post by Ksingh30
Is there some kind of tool that can let me do the following.
I have a fairly large C++ app I am working on. and theres lots of methods in there that I think are never invoked. is there a tool that can go through my code and tell me which methods never get called?


There are a variety of code coverage tools. I used one at my last company, but the name is escaping me ATM. A quick (and $$ free) way is to simply add a line to the beginning of each method (perhaps just the suspect ones to start), and have the ability to enable or disable logging off this line. Output it in a nice, easy to check format. Then you can use a tool (perhaps sed & awk) to retrieve the useful parts of the output. If you can figure out what is called, it's then easy to figure out what hasn't been called.

I will say, though, that unused functions aren't necessarily bad, if they're general purpose and reusable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this