1

I've being using Visual Studio 2005 for several years, and usually projects grow and grow, but now I have a project that is going down size, I'm taking away a big chunk of it (almost half of it)... I expected that by deleting the entry point function the compiler would give me a list of unrefrenced functions which I would then delete, and so on until the whole unneeded code was completely deleted... but to my surprise no "unreferenced function" was listed.

I recall in the old days of Turbo C, the compiler immediately protested if there was a function that was not called anywhere... I don't understand why Visual Studio doesn't have this feature, I already checked the properties page throughout and can't find something to help me to get rid of the dead code in a systematic way.

Can Visual Studio detect dead code? if so, how do I enable such feature?

  • 2
    Visual Studio 2005 and Turbo C... eww... – Mysticial Mar 29 '13 at 18:14
  • What about libraries? Do you have to use each and every function from them too? – Bartek Banachewicz Mar 29 '13 at 18:16
  • The link that @HansPassant posted provides some great information. I'll give Gimpel's PC-Lint a big thumbs up. And not just for doing dead-code identification, but for a generally *excellent* tool that should be part of everyone's build process. – Nik Bougalis Mar 29 '13 at 19:20

2 Answers2

0

You can use code coverage to determine what parts of your program are being used. Of course you have to be careful because only the code paths taken in the instrumented run are taken into consideration. But anyway this can prove a good start in solving your problem.

Visual Studio 2010 Native C++ Code Coverage Coloring Not Working

I don't think you have C++ code coverage in Visual Studio 2005 but you can try converting your solution to a newer version.

http://msdn.microsoft.com/en-us/library/dd537628.aspx

Community
  • 1
  • 1
Cristian Bidea
  • 679
  • 4
  • 12
  • Code coverage was my first thought. But code coverage gives you list of functions that are never called during TESTING. What is needed here list of functions that are not called at all (like, there is no codepath from main() that calls Foo()). – glagolig Mar 29 '13 at 19:13
0

Did you try enabling level-4 warning? Dead code is not linked into binaries by default, but you can enable warnings each time this happens: http://msdn.microsoft.com/en-us/library/z85eyax0(v=vs.71).aspx

glagolig
  • 1,100
  • 1
  • 12
  • 28