Let's say I have a struct named 'Foo' and inside of that I have a 2d array of pointers
typedef struct Foo {
Stuff* (*stuff)[16];
} Foo;
I have an initializeFoo function like so that allocates memory for the whole object
void initializeFoo(Foo **foo) {
*foo = (Foo*)malloc(sizeof(Foo));
}
However, with just that I result in a Segmentation fault(core dumped) when running my program I was thinking that I need to allocate the memory for *stuff, but how would I do that? And would I stick that in the initializeFoo function?
My guess would be to use:
(*foo)->stuff = (Stuff*(*)[16])malloc(sizeof(Stuff))
Can someone help me out?