我可以在运行时之前知道命令行参数的物理地址吗? [英] can i know the physical address of command line arguments before runtime ?

查看:98
本文介绍了我可以在运行时之前知道命令行参数的物理地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时之前找出命令行参数的物理地址(argv [i](如果有多个,则全部使用)).具体来说,编译器或OS可能在调用main之前将命令行值推入了堆栈,并在执行时传递了指向main的指针,该指针指向参数数组(如果我的知识 rite 是正确的),这样就可以在运行时之前知道其物理地址吗?

I want to find out the physical address of the command line arguments ( argv[i] (all of them if more than one )) before run time . To be specific , the compiler or OS might have pushed the command line values into the stack before calling main , and passing a pointer to main on execution which points to the argument array ( if my knowledge is rite right) so is it possible to know the physical address before runtime ?

推荐答案

好吧,它们可以存储在相对于main地址的某个地方,但不是一般. main在代码部分,但参数是数据.我建议您打印出argv和main的地址,看看它们是否保持关联...但是即使这样,它以后也可能会更改.

我收到一封电子邮件,说有评论,但这里没有显示.无论如何,您可以简单地执行
Well, they could be stored somewhere relative to the address of main, but not generally. main is in the code section, but the arguments are data. I suggest that you print out the addresses of argv and main and see if they maintain a relationship ... but even if so, it could change later.

I got email saying there was a comment but it isn''t shown here. Anyway, you can simply do
printf("%ld\n", (char*)argv - (char*)main);

...不能保证按C标准工作,但应在常规实现中工作.但是,我怀疑这将是一个固定值还是即使它是固定值也有用.

... this is not guaranteed to work by the C standard, but should work in normal implementations. However, I doubt that this will be a fixed value or that it would be useful even if it were.


否;就像您在Stack Overflow上被告知的那样,它可能会有所不同.
No; as you were told on Stack Overflow, it can vary.


这篇关于我可以在运行时之前知道命令行参数的物理地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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