unused method

Started by
3 comments, last by Rydinare 16 years, 1 month ago
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?
Advertisement
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
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.
You can just comment out your whole header file and uncomment declarations till it compiles. That'd be rather tedious though.
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.

This topic is closed to new replies.

Advertisement