可能重复:
Getting a stack overflow exception when declaring a large array一个奇怪的分段错误
我的系统是x86-64 linux
这里是我的简单代码:
#include<stdio.h>
#define N 1024
int main()
{
int a[N][N];
int b[N][N];
printf("hello world\n");
return 0;
}
而且从objdump的它的汇编代码:
00000000004004fc <main>:
4004fc: 55 push %rbp
4004fd: 48 89 e5 mov %rsp,%rbp
400500: 48 81 ec 00 00 80 00 sub $0x800000,%rsp
400507: bf c4 05 40 00 mov $0x4005c4,%edi
40050c: e8 cf fe ff ff callq 4003e0 <[email protected]>
400511: b8 00 00 00 00 mov $0x0,%eax
400516: c9 leaveq
400517: c3 retq
400518: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
40051f: 00
奇怪的是这一计划将打破调用printf()
功能时。但是,如果我将N定义为512,则此程序运行良好。我不知道为什么。是否有任何堆栈大小限制,限制堆栈使用内存?
有人知道为什么吗?谢谢。
有点讽刺在StackOverflow上问这个问题 – Nemo
'ulimit -s'的输出是什么? – ThiefMaster
把a'和'b' *定义在外面怎么样? –