typedef struct
{
int blah;
int bleh;
} Foo;
typedef struct
{
int a;
int b;
Foo* arr[];
} Bar;
int main(int argc, char **argv)
{
Bar* bar = malloc(sizeof(Bar) + sizeof(Foo) * 5);
Foo foo1 = bar->arr[0];
return 0;
}
On the line where foo1 is assigned, I get "invalid initializer". If I change the type to Foo*, it compiles. But then if I do foo1->blah = 3, the program crashes.
Why is the type of array elements Foo* and not Foo? And why is the program crashing?