在编译C文件后如何找出变量的地址 [英] how to find out the address of a variable after I compile the C file

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

问题描述




我有一个C程序。我编译了uisng gcc和avr-gcc。现在编译完成后,我想知道这两个变量的地址。

我的程序。我有什么选择可以用来找出它吗?

有什么方法可以找到它吗?有人告诉我这是可能的,但是我无法找到。


提前谢谢你,

priya

解决方案

bi ** *******@gmail.com 写道:



我有一个C程序。我编译了uisng gcc和avr-gcc。现在编译之后,我想知道我的程序中两个变量的地址。我有什么选择可以用来找出它吗?是否有任何方法可以找到它?有人说这是可能的,但我无法找到。



听起来你正在寻找一个地图文件,检查编译器

文档。如果avr-gcc用于嵌入式目标,你应该能够生成一个,但是这里的细节不在这里。


-

Ian Collins。


bi *** ******@gmail.com 写道:




我有一个C程序。我编译了uisng gcc和avr-gcc。现在编译之后,我想知道我的程序中两个变量的地址。我有什么选择可以用来找出它吗?是否有任何方法可以找到它?有人说这是可能的,但我无法找到。




如果变量是除main之外的函数的本地变量,

然后它可能会或可能不会有相同的地址,每次在程序运行期间调用该函数时,



/ * BEGIN new.c * /


#include< stdio.h>


int main(无效)

{

double x;


printf(" x的地址是%p \ n",(void *)& x) ;

返回0;

}


/ * END new.c * /

- -

pete



bi ********* @ gmail.com 写道:



我有一个C程序。我编译了uisng gcc和avr-gcc。现在编译之后,我想知道我的程序中两个变量的地址。我有什么选择可以用来找出它吗?是否有任何方法可以找到它?有人说这是可能的,但我无法找到。




如果你想从程序中显示一个变量的地址你

可以使用%p作为printf格式,例如printf(" Address var1 =%p,

var2 =%p"& v1,& v2); (其中v1和v2是你的变量)。

如果你想在编译的

程序中找到变量的地址,你可能会遇到问题。考虑递归

函数的情况。每次递归调用都会在不同的
地址创建局部变量。


-

Ioan - Ciprian Tandau

tandau _at_ freeshell _dot_ org(希望现在还不算太晚)

(......它还能运作......)


Hi,

I have a C program. I have compiled it uisng gcc and also avr-gcc. Now
after compiling, I want to know the addresses of the two variables in
my program. Is there any options that I can use to find that out? Is
there any way at all to find that out? Someone told that it was
possible but I am not able to find out.

Thank you in advance,
priya

解决方案

bi*********@gmail.com wrote:

Hi,

I have a C program. I have compiled it uisng gcc and also avr-gcc. Now
after compiling, I want to know the addresses of the two variables in
my program. Is there any options that I can use to find that out? Is
there any way at all to find that out? Someone told that it was
possible but I am not able to find out.


Sounds like you are looking for a map file, check the compiler
documentation. If avr-gcc is for embedded targets, you should be able
to generate one, but the details are off topic here.

--
Ian Collins.


bi*********@gmail.com wrote:


Hi,

I have a C program. I have compiled it uisng gcc and also avr-gcc. Now
after compiling, I want to know the addresses of the two variables in
my program. Is there any options that I can use to find that out? Is
there any way at all to find that out? Someone told that it was
possible but I am not able to find out.



If a variable is local to a function other than main,
then it may or may not have the same address,
each time the function is called during the run of the program.

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
double x;

printf("The address of x is %p\n", (void *)&x);
return 0;
}

/* END new.c */
--
pete



bi*********@gmail.com wrote:

Hi,

I have a C program. I have compiled it uisng gcc and also avr-gcc. Now
after compiling, I want to know the addresses of the two variables in
my program. Is there any options that I can use to find that out? Is
there any way at all to find that out? Someone told that it was
possible but I am not able to find out.



If you want to display the adress of a variable from the program you
can use %p for printf format, e.g. printf("Address var1=%p,
var2=%p",&v1, &v2); (where v1 and v2 are your variables).
If you want to find the address of the variables in the compiled
program you may have a problem. Consider the case of a recursive
function. The local variables are going to be created at different
addresses with each recursive call.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it''s not too late)
(... and that it still works...)


这篇关于在编译C文件后如何找出变量的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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