C pointers

Wayne A. Throop throopw at xyzzy.UUCP
Tue Feb 14 01:26:57 AEST 1989


> jcrowe at shaffer.UUCP (Joe Crowe)
> 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 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??

Um.... maybe I'm being naive myself, but did you try the obvious one,
the one you declared it with?  That is,

     (*t_xyz.p_cmd_blk)[N]

"It works for me."

In particular, I did this:

    $ cc -g -o t46 t46.c
    $ mxdb t46
    Scanning executable file...
    (debug) view
        1   #include <malloc.h>
        2   struct diag_cmd { int i };
        3   struct { struct diag_cmd (*p_cmd_blk)[]; } t_xyz;
        4   main(){
    *   5     t_xyz.p_cmd_blk = (struct diag_cmd (*)[])malloc(4);
        6     (*t_xyz.p_cmd_blk)[0].i = 23;
        7   }
    (debug) breakpoint 7;continue
    Stopped at frame 1: line 7 of \t46\main, PC main+024
     breakpoint "0" taken
    (debug) evaluate (*t_xyz.p_cmd_blk)[0].i
    23
    (debug) describe t_xyz
    struct {
       struct {
          int i;
       } (*p_cmd_blk)[];
    } t_xyz;
    (debug) bye

--
The seeds of crime bear bitter fruit.
                --- Dick Tracy
-- 
Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw



More information about the Comp.lang.c mailing list