From: Fabio Miranda Hamburger <fabmirha@ns.isi.ulatina.ac.cr>
To: linux-c-programming@vger.kernel.org
Subject: n-dimension dynamic allocated array with malloc()
Date: Wed, 12 Jul 2006 15:58:59 -0600 (CST) [thread overview]
Message-ID: <Pine.LNX.4.64.0607121556330.10434@ns.isi.ulatina.ac.cr> (raw)
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
next reply other threads:[~2006-07-12 21:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-12 21:58 Fabio Miranda Hamburger [this message]
2006-07-13 3:21 ` n-dimension dynamic allocated array with malloc() Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0607121556330.10434@ns.isi.ulatina.ac.cr \
--to=fabmirha@ns.isi.ulatina.ac.cr \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).