0

If I have this:

typedef struct {
   foo_t *bar;
} foo_t;

then I get errors like error: unknown type name ‘foo_t’. I could make bar a void* and cast later, but that seems like the wrong way to go.

Is there a proper way to resolve this chicken and egg problem?

KJ7LNW
  • 1,437
  • 5
  • 11
  • 1
    Does this answer your question? [self referential struct definition?](https://stackoverflow.com/questions/588623/self-referential-struct-definition) or [How to define a typedef struct containing pointers to itself?](https://stackoverflow.com/q/3988041/364696) The second is the more exact duplicate (just found the first one earlier, and it's similar). I actually prefer the second solution to the second link (using the `struct` name, not the `typedef` name within the struct definition), but either works. – ShadowRanger Sep 10 '21 at 03:50

1 Answers1

1

Something like this

   typedef struct foo_t {
       struct foo_t *bar;
   } foo;

So your type is foo, which is the same as struct foo_t

Nathan Day
  • 5,981
  • 2
  • 24
  • 40
  • That works. As it turns out, the typedef and struct can both be named foo_t so I don't have two names floating around. – KJ7LNW Sep 10 '21 at 03:58