# Unused function detection

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

## Recommended Posts

I started a project thinking I would need certain functions. At one point I thought of an alternative way to implement the functionality needed. I left the original functions in and wrote the new ones. Today I found that nothing uses the old functions and that it was safe to remove them. While I know that the gcc/g++ compiler will detect unused variables and warn me about them, it didn't seem to notice that the functions went unused. Of course, it shouldn't actually warn me since it would be annoying to be warned about not using each and every function available. Still, I would like a tool that would let me check for such things once in awhile. Is there a tool that would basically analyze my code and say, "Hey, this function is declared and defined, but it isn't actually used anywhere"?

##### Share on other sites
-Wunused-function, which is also enabled when you do -Wall.

Your programs should probably always be compiled with -Wall, possibly -Wextra (or -W depending on GCC version) and maybe even -pedantic.

##### Share on other sites
Hey cool someone else from Chicago :) anyhow I don't know of any tools that will do that for you but the way I've always done it was comment out what you think might not be used with /* */ compile it then check for errors during compile time and also inside the program itself. I will check around to see if there are any such tools.

Edit: hmm never knew about that compile flag for gcc :) might have to check it out sometime.

##### Share on other sites
I have the following line in my Makefile:

Just a thought

Quote:

• 15
• 21
• 21
• 11
• 25