Whether we're maintaining unfamiliar code or checking out the implementation details of an Apache module it can help if we can quickly traverse the code and build up an overview of what we're looking at. Grep serves most of my daily needs but there are some cases where it just wont do.
Here's a common example of how it can help. To find the definition of a PHP function I'm interested in I can type this at the command line:
grep -r "function myfunc" .
This could be adapted very quickly to C or C++ if we know the return type, but things become more complicated if, say, I want to list every method that my class provides:
grep "function " ./src/mine.class.php
Since there's no single keyword that denotes a function or method in C++ and because it's generally more complex syntax, I think I'd need some kind of static code analysis tool, smart use of the C Preprocessor or blind faith the coder followed strict code guidelines (# of whitespace, position of curlies etc) to get these sorts of results.
What would you recommend?
Helix QAC is an excellent static analysis testing tool for C and C++ code from Perforce (formerly PRQA).
Static analysis identifies defects before you run a program (e.g., between coding and unit testing). Dynamic code analysis identifies defects after you run a program (e.g., during unit testing). However, some coding errors might not surface during unit testing.
Static analyses are distinct from dynamic analyses such as valgrind, which extract facts from a program as it runs, and model checking, which verifies the correctness of a separate external specification of a program. Dynamic and static analyses are often used in tandem across many applications.
CppDepend is a commercial static code analysis tool for C++.
Run it through doxygen. It will complain about lack of commenting , but it will still produce call graphs and list all the functions. Presented in HTML with links to follow code paths.
doxygen
Exuberant Ctags http://ctags.sourceforge.net/
I've only used it from time to time some time ago, and from within a text editor, but check out the list of utilities/tools which can use it:
http://ctags.sourceforge.net/tools.html
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