delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/19/22:44:23

X-Authentication-Warning: niemeyer.net: Host 200.212.2.184-as.acessonet.com.br [200.212.2.184] claimed to be computer
From: "Gustavo Niemeyer" <djgpp AT niemeyer DOT net>
To: <djgpp AT delorie DOT com>
Subject: RE: Dinamic allocation
Date: Sat, 19 Jun 1999 23:41:22 -0300
Message-ID: <LOBBKLEPLBKLOKFELHOIAELLCCAA.djgpp@niemeyer.net>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Importance: Normal
In-Reply-To: <MAPI.Id.0016.00333138303633303030303930303039@MAPI.to.RFC822>
X-MIME-Autoconverted: from 8bit to quoted-printable by niemeyer.net id XAA08085
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id WAA26413
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Hi Erik!!!

Thank you for your sugestion, I really didn't think
about this way! It certainly solves the problem. But
I'm still look for a way to allocate arrays with 2
or more indexes. If you find something about it,
please, let me know!

Thank you again.

Gustavo Niemeyer



-----Original Message-----
From: Erik Berglund [mailto:erik2 DOT berglund AT telia DOT com]
Sent: Sábado, 19 de Junho de 1999 22:19
To: djgpp AT delorie DOT com
Cc: erik2 DOT berglund AT telia DOT com
Subject: Re: Dinamic allocation



Gustavo Niemeyer wrote:

> char spans[MAXHEIGHT][MAXWIDTH];
>
> So the program runs ok. But when I try to
> use dinamic memory allocation like this:
>
> char **spans;
> spans = (char **) malloc(MAXWIDTH*MAXHEIGHT*sizeof(char));
>
> When I run the program it prints a General
> protection fault error, pointing to a loop
> that accesses the array.

The allocation seems right, but I think the declaration should be
"char *spans", and the data access later down below in your
program code should look something like:

data = spans[MAXWIDTH * y + x];

In this way, the compiler thinks spans is a simple char vector,
but that's ok, the multiplication will make it work anyway.

Hope this helps,
Erik



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019