I'm looking for a way to check if my C project, that compiles to an ELF, has unused functions, and locate them. That is functions that are declared but are not called anywhere in my code.
The solution can be one of:
The solution cannot be one of:
gprof
(some functions take days until they are called, but in the code flow you can see that they are eventually called)Thank you
If you need something exact, automated or polished, you need your compiler and build-system to team up and do it for you, somehow.
If you don't need exact results or something particularly automated or polished, then here's a very rough approximation: It'll find every word that occurs only once in all of your .c files.
find . -name \*.c -exec cat {} \; \
| tr -s '[[:space:];:,?!.|()-"<>=]' '\n' \
| sort \
| uniq -u
This could of course fail in a million ways: preprocessor tricks, comments repeating function names, functions named the same as common words used in comments etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With