Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!microsoft!t-wader From: t-wader@microsoft.UUCP (Wade Richards) Newsgroups: comp.lang.c Subject: Re: Array of pointers (in general) Message-ID: <9387@microsoft.UUCP> Date: 9 Dec 89 05:16:35 GMT References: <10468@attctc.Dallas.TX.US> Reply-To: t-wader@microsoft.UUCP (Wade Richards) Distribution: na Organization: Microsoft Corp., Redmond WA Lines: 46 Summary: Expires: Sender: Prefered-Food: Pizza Shoe-Size: 10 1/2 Followup-To: Disclaimer: I don't always agree with my boss, why should he agree with me? In article <10468@attctc.Dallas.TX.US> bobc@attctc.Dallas.TX.US (Bob Calbridge) writes: =} [...] =}My immediate need requires that I simply establish an array of pointers and =}also declare the space to which the pointers point. The data area does not =}need to have an initial content but must be reserved. Is this possible or =}is it necessary to have a previously defined data area specified to which =}the pointers are directed? Am I even being clear? =} =}Example: I want 10 uninitialized structures defined but I want to reference =}them through an array of pointers. Rather than give each structure a name =}and declare the array like =} =}struct entry *list [] = { =} &S1, &S2, &S3, &S4 =}}; =} =}can I avoid having to declare the structures S1, S2, etc. elsewhere in the =}program? I'm not sure what exactly you want, but the obvious answer (at least to me), is: struct entry *list [10] ; for( i=0; i<10; i++ ) list[i]=malloc(sizeof(struct entry)); If you want the space to be initilized at compile time, you might try: struct entry array[10]; struct entry *list[10] = { &array[0], &array[1], ... }; -- or -- struct entry *list[10] = { array, array+1, ... }; Of course this isn't much more elegant than your solution of using S1, S2, ... I may be proving my ignorance (I'm too laxy to look it up now), but I'm certain that there is no way to do this as simply as your array of pointers to character example. Hope this is some help... --- Wade