I\'m trying to remove functions that are not used from a C++ project. Over time it\'s become bloated and I\'m looking to remove functions that aren\'t used at all.
I ha
I'm pretty sure that mathematically, this can't be done in the general case. If you allow for recursion and function pointers (or first class functions) then you end up in a pretty simple reduction to the Halting Problem.
Granted, this be a case that you never have to deal with, but you should know abut it...
If you want to know, dynamically, which functions are being used you could get the (vc++) compiler to insert callcap hooks and then use those to dump out usage information.
This could be a useful compliment to static analysis based approaches, since it will see every piece of code that is entered during execution (regardless of how execution arrives there).
See http://msdn.microsoft.com/en-us/library/ms254291(VS.80).aspx for info on call profile hooks in visual studio.
If your code is simple enough static analysis might work. However C++ is very context-sensitive :/. So I personally would not even try to look for a tool in the area. At least not until CLANG is fully compliant with C++ :D
I hope you have unit-tests, I would get visual studio to compile code which generates a runtime profile and then farm the function names's (with a scripting language) from the generated profile. If you have covered all of the use-cases (either manually or with unit-tests) in your application you should be able to identify the least used (or never-used) functions. Then you can use the mark-one eyeball to trim down the source-base.
There is nothing like doing It manually though :D
The excellent (and free) Source Monitor static analysis tool, from http://www.campwoodsw.com/ can give you counts of the number of calls to a method, which I think is what you want.
Edit: Seems to be my evening for screwing up. The calls metric does not in fact do what I thought it did. Still, SM is an excellent tool so I hope that bringing it to people's attention has done some good!
Sounds like you need a code coverage tool. There's a list of them in this wikipedia article.
Use __declspec(deprecated)
in front of the function declaration you want to get rid of. That will throw up compile warnings if that function is actually used at compile time.