I would like to compose a structure that possesses a contiguous array of flexible members that are, in turn, aggregation of few data fields. With that code pattern I want to: a) store multiple relevant data fields, b) have an array of such instances and c) destroy them all as simply as free(). The code bellow seems do the job:
struct s_symm_root{
unsigned int size_c;
struct {
unsigned int symm_color;
t_symm_gnrtr symm_gnrtr;
} _[];
} *symm_root;
unsigned int SIZE_C = 10;
symm_root = (struct s_symm_root*)malloc( sizeof(struct s_symm_root) + sizeof(*((struct s_symm_root*)NULL)->_) * SIZE_C );
symm_root->size_c = 1;
symm_root->_[0].symm_color = 2;
printf(" %d, %d, %ul.\n", symm_root->size_c, symm_root->_[0].symm_color, sizeof(*((struct s_symm_root*)NULL)->_));
free(symm_root);
My questions is if I can improve it a bit, specially, get rid of that ugly '_' somehow? I thought about anonymous structures but IDK how to implement them...
Thanks for suggestions!