Cydox wrote: > For the record, I think the most correct definition, in terms of "this is how > much memory you should allocate for a struct with a flexible array member" is > this: > > ```c > max( > sizeof(struct S), // always at least the size of the struct itself > round_up( > alignof(struct S), // size must be a multiple of alignment > offsetof(struct S, fam) + count * sizeof(((struct S *)0)->fam[0]) > ) > ) > ```
I mean it would be useful to round up to the alignment for when you wanne have an array of the structs, but I'm not sure this is actually required by the standard. Do you have more justification for the alignment requirement on structs containing FAMs? I would argue the minimum "legal" amount to allocate is: ```C max( sizeof(struct S), offsetof(struct S, fam) + count * sizeof(((struct S *)0)->fam[0]) ) ``` https://github.com/llvm/llvm-project/pull/112636 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits