Possible Duplicate:
Getting a stack overflow exception when declaring a large array
My system is x86-64 linux
and here is my simple code :
#include<stdio.h>
#define N 1024
int main()
{
int a[N][N];
int b[N][N];
printf("hello world\n");
return 0;
}
And its assembly code from 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
The weird thing is this program will break down when calling printf()
function. However, if I define N to be 512, this program works well. I have no idea why. Is there any stack size limitation which limits the memory use by stack?
Does anybody know why? Thanks.