main() { double x[1048181]; int n = sizeof(x); }

Alexander Zvyagin zvyagin@gams.ihep.su
Wed Jan 5 11:10:00 GMT 2000


Dear GCC developers,

to my great surprise this code

main() { double x[1048181]; int n = sizeof(x); }

cause "Segmentation fault" under gcc-2.95.2.

$ g++ 2.c
$ a.out
Segmentation fault

$ g++ -O1 2.c
$ a.out

There is no "seg.fault" if optimisation is ON!

This is difference in assembler code:

$ diff 2bad.s 2good.s 
14c14
<       subl $8385464,%esp
---
>       subl $8385448,%esp


There are not any problems if value 1048180 (or smaller) is used.
So 1048181 (and bigger) is, hmm..., magic number.

With best wishes,
Alexander Zvyagin.



More information about the Gcc-bugs mailing list