declaring an array of pointers to malloced arrays
John Campbell
jdc at naucse.cse.nau.edu
Mon Nov 5 08:23:56 AEST 1990
Help? I built a structure:
typedef struct { int loc, bstart, bend;} seeks;
and I want to store a bunch of these seek triples in malloced space.
But I also want to be prepared for up to _NFILES number of malloced
arrays. What I ended up doing was the following lie:
static seeks *fdseeks[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Then, after mallocing in an init() routine, when I wanted to access the
10'th seek triple for the 3rd file I'd do this ugly trick:
seeks *seek_p = (fdseeks[3] + 10*sizeof(seeks));
and seek_p->loc would be the file 3's 10'th seek location. What I'd
rather say, however, is fdseeks[3][10]->loc (or even fdseeks[3][10].loc).
Note: cdecl warns me that struct seeks (*fdseeks[20])[], with it's
arbitrary array ([]) is not supported by the 'C' language.
Now remember, BE NICE; some of us morons post to learn, not to start
fights!
--
John Campbell jdc at naucse.cse.nau.edu
CAMPBELL at NAUVAX.bitnet
unix? Sure send me a dozen, all different colors.
More information about the Comp.lang.c
mailing list