C typedef coding style for opaque structs -


so understand typedefs acceptable opaque structs can manipulated accessor functions.

is appropriate way use opaque typedef structs self referential within accessor functions?

    typedef struct foo {         struct foo *bar;         int member;     } foo1;      foo1 * blah1 = (foo1*) malloc(...);     blah1->bar->member = 999; 

the alternative this:

    typedef struct {         struct foo* bar;         int member;     }foo;  

so when this:

    foo * blah1 = (foo*) malloc(...);     blah1->bar->member = 999;  

you'll error:

    dereferencing pointer incomplete type 

this question similar asking forward declaration of unnamed struct. cannot forward declare unnamed struct , similarly, cannot use member in same struct have shown:

typedef struct {     struct foo* bar;     int member; }foo;  

this because compiler cannot know type. struct foo not same unnamed struct typedef foo. previous stackoverflow answers explain reason:
forward declaring typedef of unnamed struct
and
forward declarations of unnamed struct


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -