C pointers

Stan Friesen sarima at gryphon.COM
Tue Feb 14 08:01:17 AEST 1989


In article <1707 at shaffer.UUCP> jcrowe at shaffer.UUCP (Joe Crowe) writes:
>
>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??
>
	Even though I have seen one article with the correct solution,
(you probably meant 'struct diag_cmd *p_cmd_blk'), I will put in my two
cents worth.  This confusion between pointers to the first element of an
array and pointers to arrays is very common.  I would recommend that Mr
Koenig's "C Traps and Pitfalls" become standard reading for everyone
learning 'C'. It has an excellent chapter on just this issue, and is
probably worth the price just for that chapter alone.

-- 
Sarima Cardolandion			sarima at gryphon.CTS.COM
aka Stanley Friesen			rutgers!marque!gryphon!sarima
					Sherman Oaks, CA



More information about the Comp.lang.c mailing list