Any program or trick to find the definition of a variable?

前端 未结 8 1031
梦谈多话
梦谈多话 2021-01-02 09:01

Many times when I am watching others code I just want to find where and how a variable is defined. Normally what I do now is look for the type of the variable until I find t

相关标签:
8条回答
  • 2021-01-02 09:46

    Edit: OK, you say you're using C++. I'm editing my response. I would use the C preprocessor and then grep for the variable. It will appear in the first place.

    cpp -I...(preprocessor options here) file.cpp | grep variable
    

    The C preprocessor will join all the includes that the program uses, and the definition has to be before any usage of that variable in the file. Not a perfect thing, but without an IDE or a complete language description/managing tool, you only have the text.

    Another option would be using ctags. It understands the C and C++ syntaxes (among others), and can be searched for variables and functions using command line tools, emacs and vi, among others.

    0 讨论(0)
  • 2021-01-02 09:47

    If you work in Microsoft Visual Studio (which I think you could use for C++ as well, but would require working on a Windows workstation) there's an easily accessible right-click menu option for "Go to Definition...", which will take you to the definition of any currently marked variable, type or method.

    0 讨论(0)
提交回复
热议问题