>Then you have to malloc the struct to be the sizeof the struct + whatever size you want the array to be.
Ultra pedantic, but you actually do not need to alloc struct+size; you want something like:
// A flexible array member may have lower alignment requirements than the struct
// overall - in that case, it can overlap with the trailing padding of the rest
// of the struct, and a naive sizeof(base) + sizeof(flex) * count calculation
// will not take into account that overlap, and allocate more than is required.
#define SIZEOF_FLEX(type, member, count) MAX(sizeof(type), offsetof(type, member[count]))
I'm sure there's a more elegant way to calculate this, but I am no macro master.
Ultra pedantic, but you actually do not need to alloc struct+size; you want something like:
I'm sure there's a more elegant way to calculate this, but I am no macro master.