https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116016
Alejandro Colomar <alx at kernel dot org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |alx at kernel dot org --- Comment #49 from Alejandro Colomar <alx at kernel dot org> --- For reading the counted_by value, that is, for reading the number of elements in the FAM, I'm implementing a __lengthof__ operator, which returns the value that the typical ARRAY_SIZE() macro returns, but also works with FAMs declared with this attribute (and I also want to make it work on function parameters declared as arrays). Consider that for your design of a builtin for setting the counted_by value, since you don't need to have a built-in for reading the value. ;) <https://inbox.sourceware.org/gcc-patches/p33myw2zqvtysc3ayfygcvarw4ka3wwltycqjyehdgy64wsgug@ewi3uvid6rrb/T/> That is, __lengthof__ should be useful in all of the following cases: #define memberof(T, m) (((T *) NULL)->m) struct s { size_t n; int fam[] __attribute__((counted_by(n))); }; __attribute__((access(read_only, 3, 4))) void f(size_t n1, int p[n1], int q[], size_t n2) { int a[3]; size_t m; struct s *s; m = offsetof(struct s, fam) + sizeof(memberof(struct s, fam)[0]) * 7; s = malloc(m); assert(__lengthof__(a) == 3); assert(__lengthof__(p) == n1); assert(__lengthof__(q) == n2); assert(__lengthof__(memberof(struct s, fam)) == m); }