Mail Archives: djgpp/1998/04/26/12:15:24
On Sun, 26 Apr 1998 leger_v AT bluewin DOT ch wrote:
> void main(void)
> { int i,j;
> unsigned long *test[10];
>
> for(i=0;i<10;i++)
> test[i]=(unsigned long *)malloc(64000);
>
> for(i=0;i<10;i++)
> for(j=0;j<64000;j++)
> test[i][j]=10;
> }
> And this program crashes on my computer.
Of course, it will crash! "malloc(64000)" allocates 64K BYTES, not 64K
LONGS, so you are referencing in the loop more than you have allocated!
You need to say "malloc(64000*sizeof(long))" to get what you want without
crashing.
- Raw text -