------- 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

Reply via email to