Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Showing function definitions and references

Credits go to Elias, Gideon Weems, GullRaDriel, and Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
Showing function definitions and references
Peter Hull
Member #1,136
March 2001

Does anyone know of a tool which can run on a set C (and maybe C++) files and give a list of where all functions are defined and where they are used? If you've used an IDE it's like a combination of 'source browser' and 'find all references'

Reason - I want to look for functions that are never used and could be removed, also ones that are only ever called from one file and therefore could be static to that file.

Thanks!

GullRaDriel
Member #3,861
September 2003
avatar

I would use compiler flags to spot unused function @ compilation && doxygen to generate the functions relations diagrams to see the caller graph & all.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Thomas Fjellstrom
Member #476
June 2000
avatar

ctags may be what you're looking for. (not 100% sure).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Gideon Weems
Member #3,925
October 2003

ctags may be what you're looking for

I second this. There is also gtags, which works really well with Python in addition to C.

Peter Hull
Member #1,136
March 2001

Thanks all!

ctags (unless I am mistaken) finds where each function is defined but doesn't say anything about the call graph.

doxygen - I didn't know it would do this. Bravo, mon vieux! It generates the call graph very nicely but nothing in the graph shows where the functions are defined, although doxygen must have that information somewhere. Example below.

{"name":"610766","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/f\/7fcec657ad22d6eb1cea1f852a8275a5.png","w":552,"h":337,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/f\/7fcec657ad22d6eb1cea1f852a8275a5"}610766

gtags - is this the same as gnu global? Looks promising, will have to do some research.

Elias
Member #358
May 2000

cppcheck --enable=unusedFunction

Although running it on Allegro sources, it has a lot of false positives.

--
"Either help out or stop whining" - Evert

GullRaDriel
Member #3,861
September 2003
avatar

Peter: click on the box and it gets you to the function definition page, which mention file, line, parameter. Only white box are clickable, as the grey ones are terminaisons.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Gideon Weems
Member #3,925
October 2003

gtags - is this the same as gnu global?

Yes, though if call graphs are what you're after, perhaps cflow would be more appropriate. (I've never used it, so no endorsement.) This handy page lists more options.

Peter Hull
Member #1,136
March 2001

I think gtags does what I want. Thanks all, especially Gideon that page was very helpful
Pete

Gideon Weems
Member #3,925
October 2003

\o/

If you make any pretty graphs, please share.

Go to: