任何程序或技巧找到变量的定义? [英] Any program or trick to find the definition of a variable?

查看:164
本文介绍了任何程序或技巧找到变量的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多时候,当我看着别人的代码,我只想找到变量在哪里和如何定义。通常我现在做的是查找变量的类型,直到我找到定义,这是非常耗时。我想有一些工具,可以帮助我在这个讽刺的情况。任何建议在一些工具或命令帮助我在这项任务?。



我知道使用GUI和创建项目这是自动完成我说的方式做到这一点没有GUI。我只工作在文本模式。我在Linux下运行,我正在使用C / C ++,但欢迎其他语言的建议。



非常感谢。



可能的解决方案



Michel在他的一条评论中提出了一个简单的有效解决方案,再次定义变量,在编译时,编译器将通知前面的定义。当然,要应用这个解决方案,我们需要先考虑变量的局部性。

解决方案

>:OK,你说你在使用C ++。我正在编辑我的回复。我将使用C预处理器,然后grep的变量。它将出现在第一位。

  cpp -I ...(这里的预处理器选项)file.cpp | grep变量

C预处理器将加入程序使用的所有包含,之前在该文件中使用该变量。



另一种选择是使用 ctags 。它理解C和C ++语法(以及其他),并且可以使用命令行工具,emacs和vi等搜索变量和函数。


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 the definition, that is very time consuming. And I guess that there are some tools that can help me in this rutinary situation. Any suggestion in some tools or commands to help me in this task?.

I know that using a GUI and creating a project this is done automatically I am talking of a way to do this without a GUI. I am working with only text mode. I am running under Linux and I am using C/C++, but suggestions for other languages are welcome.

Thanks a lot.

A possible solution

Michel in one of his comments propose a simple an effective solution define again the variable, in that case in compilation time, the compiler will inform where is the previous definiton. Of course to apply this solution we need to think previously in the locality of the variable.

解决方案

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.

这篇关于任何程序或技巧找到变量的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆