const int hello= 0x1111;
int main(){
}
我构建了一个非常简单的代码,并使用它进行编译
gcc t.c -g -o t.out
我可以使用 objdump 或 nm 或任何工具来确定 const 变量值吗? 我总是找到变量“hello”的地址,但找不到值
谁能帮帮我,非常感谢
最佳答案
示例代码
const int hello = 0xdeadbeef;
int main()
{
return 0;
}
编译
gcc-4.9 -W -Wall -Wextra -pedantic -std=c11 fortests.c -o fortests
转储内容
objdump -xDSs fortests | less
(转储有点太多,但没有任何成本,所以...嗯...)并搜索 hello
0000000000400594 g O .rodata 0000000000000004 hello
这意味着它位于 .rodata
部分中。我们明确要求 objdump 列出所有部分的内容,因此我们在这里得到了值 0xdeadbeef。
Contents of section .rodata:
400590 01000200 efbeadde ........
^^^^^^^^
here ||||||||
现在应该很清楚为什么你找不到它了。
关于c - C中,编译时查找全局const变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40477868/