C pointers

Larry Jones scjones at sdrc.UUCP
Sat Feb 11 09:48:44 AEST 1989


In article <1707 at shaffer.UUCP>, jcrowe at 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 at sdrc.UU.NET
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150                  AT&T: (513) 576-2070
"When all else fails, read the directions."



More information about the Comp.lang.c mailing list