【发布时间】:2012-12-29 05:19:02
【问题描述】:
可能重复:
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 <puts@plt>
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 上问这个有点讽刺
-
ulimit -s的输出是什么? -
把
a和b的定义放在outside怎么样? -
Weired Seg 故障?不。这是应该的方式......
-
尼莫,我明白了。在 StackOverflow 上问这个问题很讽刺。 :-)
标签: c