Mail Archives: djgpp/1997/03/03/02:58:08
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 -