www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/03/02:58:08

From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP Structs
Date: 3 Mar 1997 05:09:11 GMT
Organization: The National Capital FreeNet
Lines: 48
Message-ID: <5fdmdn$mn8@freenet-news.carleton.ca>
References: <01bc2673$a4dbe420$8e54dec2 AT satan>
Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
NNTP-Posting-Host: freenet5.carleton.ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


Also: no typecast is needed to assign the result of a malloc or calloc to
a pointer.

int *bunch_of_ints;
bunch_of_ints=malloc (3000*sizeof(int));

will work just as well as 

int *bunch_of_ints;
bunch_of_ints=(int *)malloc (3000*sizeof(int));


and is more readable.


Secondly, if you want a HUGE 2-dimensional array, define a pointer to a
2-dimensional array. It's obscure but possible:



struct defPt (*View)[MAX_Y];      /* Pointer to a MAX_Y element array of
                                     struct defPt */
struct defPt a;
View=calloc(MAX_X*MAX_Y,sizeof(struct defPt));

.
.
.
View[x][y]=a;
View[a][b].sx=95;           /* Notice dot instead of arrow. */

and these are true.

View is type struct defPt (*)[MAX_Y]     (pointer to array)
View[n] is type struct defPt[MAX_Y]
View[i][j] is type struct defPt

&(View[i][j]) == View[i]+j
&(View[i]) == View+i
&(View[i][j]) == *(View+i)+j

--
    .*.  Where feelings are concerned, answers are rarely simple [GeneDeWeese]
 -()  <  When I go to the theater, I always go straight to the "bag and mix"
    `*'  bulk candy section...because variety is the spice of life... [me]
Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh

- Raw text -


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