开发者

Finding a function definition using a call in C++

I'm trying to understand the source code of a fairly large C++ project. The source wasn't written with an IDE, so I don't have a "goto" button to go straight to the function definition.

For example:

srand();

I want to find out exactly where the function srand() is defined.

The only method I can come up with is manually checking all the header includes to recursively find the declaration and the corresponding file for the definition.

This is a linux environment and the source is compiled w开发者_如何学编程ith g++ (using cmake).


Look into the ctags program.

ctags generates a file with information on the locations in the code where each identifier is used. It is then possible to use a plugin for your editor of choice that will allow you to jump to the definition of any identifier. (very mature ctags plugins exist for Vim and Emacs, and probably for most other popular editors as well.)


If you are using VI you can shift+k that will open it in a man page, if there is one for this word. I believe it automatically is set to search in man(3) but i'm not 100% sure. At least this way you can know wether it's a system function or not.

Another option is to use Doxygen to setup the call graphs and let it generate the source (even if there are no comments). With the call graph you can easily spot from where each function is coming from.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜