The sole purpose of using a flexible array member as the last member of a struct is to allow data of variable size to be appended directly after the struct in the same memory segment, and then access that data in a well-defined way.
That means that an array of pointers is often not what you want there, but rather an array of data. It could make sense in some special cases to allocate an array of pointers there, but if it does so in this case, I can't tell.
The normal use-case would be this:
typedef struct FriendStack {
bool is_resizable;
size_t max_size;
Friend stack[];
} FriendStack;
size_t n = something_variable;
FriendStack* fs = malloc( sizeof *fs + sizeof(Friend[n]) );
...
free(fs);
Now if the intention is to actually have Friend* stack[]
instead, the syntax for allocating it is the same as above, except it becomes sizeof(Friend*[n])
in malloc. And you'd need an additional loop to allocate something for each pointer:
for(size_t i=0; i<n; i++)
{
fs->stack[i] = malloc(...);
}
But unlike the first version, this creates segmented chunks in multiple locations on the heap, so it is significantly slower and the code turns more complex overall.