是否有可能找出变量名,指针指向? [英] Is it possible to find out the variable name, the pointer pointing to?

查看:80
本文介绍了是否有可能找出变量名,指针指向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能得到数组的名字的指针指向?

Is it Possible to get the name of array the pointer pointing to?

例如:

 char name[20];
 char *p = name
 int door_no;
 int *q = &door_no

在上面的例子中我们给数组的基址与阵列名称和指针指向到 door_no 但如果,我一定要知道数组所指向的变量的名称是什么?什么是所指向的变量名指针?是否可以?我试着来到这是不可能的结论但我仍然想获得解决方案。你觉得是什么人?有没有什么办法,使这可能吗?

In the above example we are giving the base address of the array with the array name and pointer q pointing to door_no but what if, I have to know the name of the variable the array is pointing to? What is the variable name pointer q is pointing to? Is it possible? I tried and came to the conclusion that it's not possible but still I am trying to get the solution. What you think guys? Is there any way to make it possible?

推荐答案

没有,你不能这样做。变量名称不连的存在的后您的code编译和链接(除非你保持周围调试信息),所以你不能在它在运行时得到的。

No, you can't do that. The names of variables do not even exist after your code is compiled and linked (unless you're keeping debugging information around), so you can't get at it at run time.

在C(相对于非常动态语言如JavaScript或古典的Lisp这样的),在的变量名的作用是告诉当你提到的编译器/连接你指向的声明在源$ C ​​$ C的变量。一旦这些连接已经作出,并在编译器的内部数据结构psented重新$ P $,对于名字没有进一步使用(再次,除了调试和/或$ P $错误消息从编译器ptty印刷)。

In C (in contrast to very dynamic languages such as JavaScript or classical Lisp), the only role of variable names is to tell the compiler/linker which declaration you're pointing at when you mention a variable in the source code. Once these connections have been made and represented in the compiler's internal data structures, there is no further use for the names (again, except for debugging and/or pretty-printing of error messages from the compiler).

这篇关于是否有可能找出变量名,指针指向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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