可能重複:
C programming, why does this large array declaration produce a segmentation fault?C(最大值)的大小在主
這是我第一次來這裏很抱歉,如果我打破一些規則,或者如果這已經回答過了。 我最近做了一個C程序中,我有
char buff[NR][1024*1024];
矩陣我需要NR = 128。因此,該程序將alocate 128MB。這是在main()中。我在有足夠內存的幾個系統上嘗試過,沒有編譯錯誤。在運行時,我收到所有系統上的分段錯誤。它適用於NR = 7,但不是8. 我將該代碼移到了主外部,使其成爲全局代碼。它甚至沒有崩潰128. 有誰知道爲什麼會發生這種情況? 編譯器是GCC
[C編程,爲什麼這個大數組聲明會產生分段錯誤?](http://stackoverflow.com/questions/3049934/c-programming-why-does-this-large-array-declaration -produce-a-segmentation-fault) – 2010-07-15 13:32:33