#include <stdio.h>
int doHello(){
doHello();
}
int main(){
doHello();
printf("\nLeaving Main");
return 0;
}
当您运行此程序时,程序在屏幕上没有打印出“Leaving Main”消息就退出了。这是堆栈溢出的情况,因此程序终止,但我在命令窗口中没有看到任何错误消息。(在Windows/Cygwin上运行)
Q1. 在doHello函数中我没有声明任何局部变量,但堆栈仍然被使用。这是因为
- 返回值
- 有关函数调用的信息被存储吗?
澄清
Q2. 如何调试此类问题?我不是要求调试我上面提到的无限循环。例如:
#define SIZE 512*1024
void doOVerflow(){
char str[SIZE];
doHello();
}
void doHello(){
char strHello[256]; // stack gets filled up at this point
doNothing(); // program terminates and function doNothing does not get called
}
编辑:
Q3. 运行时栈存储了哪些信息?