如何在文件中查找指针变量列表 [英] How to find list of pointer variables in a file

查看:93
本文介绍了如何在文件中查找指针变量列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我想列出/显示文件中使用的所有指针.请告诉我该怎么做.

Hi.

I want to list/display all pointers used in a file. Please tell me how to do this.

推荐答案

不清楚您为什么会需要这样做,但是这里有我的注释:问题不能有严格的解决方案,因为它的定义不明确.

第一个问题是C ++文件不是功能单元(不是类,不是可执行文件或类似的文件),而只是一些文本.从隔离的文件中,并非总是能够识别某个变量或函数参数是否为指针.更普遍的问题是指针本质上是一个运行时概念.严格来说,不能将指针定义为某些程序代码文本的构件.两个不同的变量可以表示指向同一对象的指针.你会分开列出还是不列出?相反,在运行时,一组指针不必与某些名称或代码的任何工件相对应,那么如何列出它们呢?很难说出编译期间的状态.取一个常规的链表.所有这些都与指针链接在一起,这些指针明显不同,但仅在运行时出现.

而且甚至不要提及根据代码文本预测运行时间的可能性-在一般情况下,这是绝对不可能的.如果您不了解或不想学习它,请先阅读重要的停止问题,以及有关该问题的基本定理,可计算性理论的基本定理. i>:
http://en.wikipedia.org/wiki/Halting_problem [ http://en.wikipedia.org/wiki/Computability_theory_%28computer_science%29 [ ^ ].

你有主意吗?因为这是不适的问题,所以不应该解决.而且我认为您不能发明"任何严格的问题表述或任何有意义的表述.

—SA
Not clear why would you need this, but here is my note on it: the problem cannot have a strict solution, because it is not well defined.

First issue is that a C++ file is not a functional unit (not a class, not an executable or something like that), but just some text. From an isolated file, it''s not always possible to recognize if some variable or a function parameter is a pointer or not. The more general problem is that the pointer is essentially a run-time notion. Strictly speaking, a pointer cannot be defined as an artifact of the text of some program code. Two different variables can present the pointer to the same object; would you list them separately or not? Inversely, during run time a set of pointer does not have to correspond to some names or any artifacts of the code, so how to list them? This is something strictly impossible to tell what it is during compile time. Take a regular linked list. It is all linked with the pointers, these pointers are distinctly different but appears only during run time.

And don''t even mention the possibility of prediction of run time based on the text of the code — this is strictly impossible in general case. If you don''t understand it or want to learn about it, please start from reading about the important halting problem, and the fundamental theorem about it, the fundamental theorem of computability theory:
http://en.wikipedia.org/wiki/Halting_problem[^],
http://en.wikipedia.org/wiki/Computability_theory_%28computer_science%29[^].

Are you getting the idea? As this is the ill-posed problem, it should not be solved. And I don''t think you can "invent" any strict formulation of the problem or any formulation which would make sense.

—SA


让我尝试重述您的问题.您是否正在寻找源文件中所有表示某物指针的符号?这实际上是有效的问题.

在过去,我们有所谓的交叉引用生成器,它生成所有程序变量的列表,按名称或类型排序,并将所有出现在源文件中的变量排序.我认为这至少会对您有很大帮助.如果适合您的需求,只需在"C ++交叉引用"下使用google,您就会发现很多有趣的工具.

如果您试图找到所有指针来解决内存泄漏或指针问题,我想指出您的另一个方向,因为有更好的方法来解决这些问题.您可以在本网站的内存泄漏检测"下找到这些内容.
Let me try to rephrase your question. Are you looking for all symbols in a source file that denote a pointer to something? This would in fact be valid question.

In the good old times we had so called cross-reference generators that produced a listing of all program variables, sorted by name or by type and with all their occurrences in a set of source files. I think that would at least help you quite a bit. If that fits your needs, just google under "C++ cross-reference" and you will find quite a few interesting tools.

If you are trying to find all pointers to solve a memory leak or dangling pointer problem I would like to point you in another direction as there are far better ways to approach those problems. You find those under "memory leak detection" on this website.


要阐明解决方案2中nv3给出的建议:

如果问题与nv3建议的某种程度上与内存泄漏问题有关,请参阅内存调试器"上的这篇文章: http://en.wikipedia.org/wiki/Memory_debugger [ ^ ].

查看本文中找到的内存调试器列表.有些工具是开放源代码的工具.

—SA
To clarify the advice given by nv3 in Solution 2:

If the problem is somehow related to the problem of memory leaks, as nv3 suggested, please see this article on "memory debugger": http://en.wikipedia.org/wiki/Memory_debugger[^].

Look at the list of the memory debuggers found in this article. Some tools are Open-Source ones.

—SA


这篇关于如何在文件中查找指针变量列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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