gpt4 book ai didi

可执行文件中的C语言变量

转载 作者:太空宇宙 更新时间:2023-11-04 05:11:53 24 4
gpt4 key购买 nike

像下面这样简单地编写 C 文件:

int main()
{
int a = 999;
return 0;
}

使用gcc编译链接后,会生成可执行文件(如.exe、.out)

但是当我用一些编辑器打开(不运行)可执行文件时,我找不到变量 'a' 的值,数字 999 在十六进制中是 0x3E7。

我的问题是:

  • 可执行文件中是否存在变量号999?
  • 如果不是,变量号存储在哪里?可执行文件在运行中如何获取变量号?

P.S: 我对.data .bss .text .etc 和汇编语言等内存部分有一点了解。即使我无法使用 ollydbg 找到它。

最佳答案

编译器没有理由将值 999 放在任何地方,因为它不会在任何地方使用。无论 999 是否在内存中,该程序都具有相同的可观察行为。

ISO/IEC 9899:TC2 - 5.1.2.3 程序执行:

  1. In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object).

关于可执行文件中的C语言变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52453420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com