I'm using -std=gnu99 when I compile. Suppose I had a struct like this:
typedef struct Foo {
char *quux;
int baz;
} Foo;
I noticed that you can initialize a 1D array of structs with NULL values in the heap like this:
Foo* bar[10] = {[0 ... 9] = NULL};
But how would I do this for a 2D array on the heap? Here is my attempt:
int depth = 10;
int length = 10;
Foo **bar;
bar = malloc(sizeof(Foo) * length);
for (int i = 0; i < length; i++) {
bar[i] = (Foo*) calloc(depth, sizeof(Foo));
}
And when I go to release this memory, would I free() 10 times, or 100 times? And what about the variable length of foo.quux?