Problem: The following code snippet compiles well (where both struct types are typedefed):
typedef struct {
int a;
float b;
} member_struct;
typedef struct {
int a;
double b;
member_struct c;
} outside_struct;
outside_struct my_struct_array[4];
However, if the typedef of the "outside_struct" is dropped:
typedef struct {
int a;
float b;
} member_struct;
struct {
int a;
double b;
member_struct c;
} outside_struct;
struct outside_struct my_struct_array[4];
I get the error:
"array type has incomplete element type 'struct outside_struct'".
And if I also drop the typedef of "member_struct", I get an extra error:
"field 'c' has incomplete type"
Question: Why it happens? Is using typedef strictly necessary here? In my code, I otherwise never use typedef for structure types, so I am looking for a way to avoid that, if possible.
struct outside_structin the second snippet. You have one instance of an anonymous struct calledoutside_struct- it is not a type