dead code location tools
Are there any tools that can find stuff like this?
Variables and functions which are never used
Headers which are #included in a file, but never used
Functions which aren't called in any of the translation units of the current project
I have a lot of left over code from previous versions of my game, which I am currently in the process of rewriting. A lot of times, I accidentally do stuff like remove a virtual function from the base class, but forget to remove all the now useless code from the derived classes.
I thought that a tool like this would help me find some types of bugs more easily and improve my source code, but I am not sure if they exist or where to find them.
I'm using Code::Blocks 8.02 with Windows Vista.
Yes such tools exist. They are called "static code analyzers". Here is a list and another list. Maybe try cppcheck. Also check if your IDE supplies similar tools. Many do. And check the command line options for your complier. Your compiler might be able to issue warnings regarding dead code.
I thought it was impossible for compilers to find dead code, because you can only tell whether a function is used in a different file during the linking stage.
One other thing you might be interested in is some type of code coverage tool. These insert code into your program that keep track of what code is actually executed. These tools can also tell you information about how your conditional statements are used(ie, in the statement if (A && B) code coverage tools will tell you not only whether the entire A && B was true, but whether it was false because of A or B). This tool gives you information based on actual runtime execution and is only useful if you really exercise the code you are testing. It can be an eye-opener though, that's for sure.
Quote:Original post by Storyyeller
I thought it was impossible for compilers to find dead code, because you can only tell whether a function is used in a different file during the linking stage.
I don't know if that would prevent all compilers, but regardless uncalled functions aren't the only dead code you can have. You might have if statements that could never become true and so the code inside would never execute. The compiler could theoretically determine this.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement