Sign in to follow this  

dead code location tools

This topic is 2964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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