【发布时间】:2016-09-17 01:21:51
【问题描述】:
我尝试使用以下 Linux 命令编译我的简单 C++ 源代码 $g++ -c foo.cpp 生成目标文件。我意识到我创建的所有宏变量都分配了一个内存地址为 0。这背后的原因是什么?为什么汇编器不给变量分配适当的内存量。
编辑:
以下是我使用的代码:
$g++ -c -g string.cpp
$objdump -dS string.o > string.o.text
以下是我的简单C++代码:
#include <iostream>
#define STRING "string\n"
using namespace std;
int main() {
int count = 3;
for (int i = 0; i < count; i++)
cout<< STRING;
return 0;
}
我的 string.o.txt 中的一行说:
callq的内存地址为0。
【问题讨论】:
-
显示代码和汇编输出。
-
欢迎来到SO,请阅读How to Ask并提供minimal reproducible example
-
这几乎肯定不是正在发生的事情。
-
0 是函数的地址,而不是参数的地址。由于该翻译单元中没有定义函数,所以后面需要填写。
标签: c++ memory memory-management compiler-construction g++