Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cwjcc!gatech!hubcap!ncrcae!ncrlnk!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: C pointers Keywords: C Message-ID: <526@sdrc.UUCP> Date: 10 Feb 89 23:48:44 GMT References: <1707@shaffer.UUCP> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 38 In article <1707@shaffer.UUCP>, jcrowe@shaffer.UUCP (Joe Crowe) writes: > Consider this a niave question. I have a structure which contains among > other things a pointer to an array of structures declared as follows: > > typedef struct XYZ > { > . > . > . > struct diag_cmd (*p_cmd_blk)[]; > . > . > } t_xyz; > > I am allocating storage for the above structures dynamically and > setting the pointer p_cmd_blk manually. All of this works. But when > I try various methods of accessing a structure member one of the array > of structures I am getting compiler errors. I have tried most combinations > but with no luck. Any ideas?? The rule of thumb is C is declarations look just like references and vice versa. (Of course, you do have to correct for the structure name being in a different place in the declaration than in the usage.) Just work it out one level at a time. The references would look like: xyz_struct - struct XYZ xyz_struct.p_cmd_blk - ptr to ary of structs (*xyz_struct.p_cmd_blk) - ary of structs (*xyz_struct.p_cmd_blk)[i] - struct diag_cmd (*xyz_struct.p_cmd_blk)[i].member - member ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@sdrc.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150 AT&T: (513) 576-2070 "When all else fails, read the directions."