找到变量定义的任何程序或技巧?

Any program or trick to find the definition of a variable?(找到变量定义的任何程序或技巧?)
本文介绍了找到变量定义的任何程序或技巧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多时候,当我在看其他人的代码时,我只想找到变量的定义位置和方式.通常我现在所做的是查找变量的类型,直到找到定义,这非常耗时.而且我想有一些工具可以帮助我解决这种日常情况.对一些工具或命令有什么建议可以帮助我完成这项任务吗?

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?.

我知道使用 GUI 并创建一个项目是自动完成的,我说的是一种无需 GUI 的方法.我只使用文本模式.我在 Linux 下运行,我使用 C/C++,但欢迎提出其他语言的建议.

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.

非常感谢.

可能的解决方案

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

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.

推荐答案

编辑:好的,你说你使用的是 C++.我正在编辑我的回复.我会使用 C 预处理器,然后使用 grep 获取变量.它会首先出现.

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

C 预处理器将加入程序使用的所有包含,并且定义必须在文件中对该变量的任何使用之前.不是一个完美的东西,但没有 IDE 或完整的语言描述/管理工具,你只有文本.

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.

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

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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)