This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/16274] Memory allocation error for arrays on stack
- From: "med04hrt at studserv dot uni-leipzig dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Feb 2007 12:17:33 -0000
- Subject: [Bug c/16274] Memory allocation error for arrays on stack
- References: <bug-16274-8826@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from med04hrt at studserv dot uni-leipzig dot de 2007-02-15 12:17 -------
(In reply to comment #0)
> The following simple c code gives segmentation fault on a GNU-Linux system
> (Redhat-9.0) running on a Pentium 4 machine with 512 MB RAM.
>
>
> Source file : test.c
>
> -----------------------------------------------------
> #include<stdio.h>
>
> int main()
> {
> int a[1024][1024];
> int b[1024][1024];
>
> b[0][0]=13;
>
> return 0;
> }
I had the same error with declaring some
double[10001][13] arrays. the program crashes right at the declaration (no
printf at the beginning is executed).
It seems to me that this happens because the static memory is just to small.
I didn't find out how to define its size, but you can solve the problem if you
allocate the memory dynamically.
#include <stdlib.h>
int **a=(int**)malloc(sizeof(int)*1024*1024);
int **bb=(int**)malloc(sizeof(int)*1024*1024);
Unfourtunately i couldn't figure out how to do the correct cast, so this
produces a warning on indexation, because the pointer types aren't identicall.
Regards
Petre
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16274