linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* n-dimension dynamic allocated array with malloc()
@ 2006-07-12 21:58 Fabio Miranda Hamburger
  2006-07-13  3:21 ` Glynn Clements
  0 siblings, 1 reply; 2+ messages in thread
From: Fabio Miranda Hamburger @ 2006-07-12 21:58 UTC (permalink / raw)
  To: linux-c-programming

Hello,

What's wrong with the following code:

[fabio@localhost projects]$ cat poc.c ; gcc poc.c ; ./a.out
main()
{
         #define A 100
         #define B 100
         #define C 100
         #define D 100
         int i,j,k,l;
         double ****array;
         //srand( (unsigned) time(0x0));
         for(i=0;i< A; i++)
         {
                 array = malloc(A * sizeof(double));
         }
         for(i=0;i< B; i++)
         {
                 array[i]=malloc(B * sizeof(double));
         }
         for(i=0;i<C;i++)
         {
                 array[i][i]=malloc(C * sizeof(double));
         }
         for(i=0;i<D;i++)
         {
                 array[i][i][i]=malloc(D * sizeof(double));
         }

         for(i=0;i<A;i++)
                 for(j=0;j<B;j++)
                         for(k=0;k<C;k++)
                                 for(l=0;l<D;l++)
                                         array[i][j][k][l] = (double) 0;

}



Segmentation fault
[fabio@localhost projects]$


Thanks for any helpy,



---
Fabio Andres Miranda
Ingenieria de sistemas informaticos
Universidad Latina - Costa Rica


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-07-13  3:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-12 21:58 n-dimension dynamic allocated array with malloc() Fabio Miranda Hamburger
2006-07-13  3:21 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).