Ansi C allows that two different structs can contain pointers to each other (also shown in structs-that-refer-to-each-other). I know that this is not a good idea in many circumstances, but that’s not the question here. Is it possible to achieve the same using typedef’ed structs?
The code below works just fine.
struct b;
typedef struct a {
struct b *bb;
} A;
typedef struct b {
struct a *aa;
} B;
But using type “B” it fails
typedef struct b B;
typedef struct a {
B *bb;
} A;
typedef struct b {
A *aa;
} B;
with
error: redefinition of typedef ‘B’
Is it possible to tell the compiler that ‘B’ will be declared later and use it in the definition of A?
You can do this instead:
Does this work for you ?