#: 15751 S12/OS9/68000 (OSK)
02-Jul-92 23:07:41
Sb: #Pointer help
Fm: Bob van der Poel 76510,2203
To: all
Can someone confirm that I'm doing this correctly? I'm trying to declare a
pointer to an array of ints. I have a index which I load dynamically, so I find
I have to do declare my pointer like this:
int (*index)[DIM2];
This lets index act the same as if static storage was allocated with:
int index[DIM1][DIM2];
I can now do something like index=malloc(sizeof(int)*DIM1*DIM2).
This appears to work, but seems to be highly un-intutitive! Is there no way I
can actually have [DIM1][DIM2] in the declaration, or at least [DIM1]? I just
get worried that a year from now when I change the index structure I'll screw
the pointer.
Also, I'm not too impressed by the way I have to calculate the size of the
array in the malloc(). But I don't see anyway around this.
There are 3 Replies.
|