Hi, Based on the discussion so far and further consideration, the following is my plan for this new attribute:
1. The syntax of the new attribute will be: __attribute__((counted_by (count_field_id))); In the above, count_field_id is the identifier for the field that carries the number of elements info in the same structure of the FAM. For example: struct object { .. size_t count: /* carries the number of elements info for the FAM flex. */ int flex[] __attribute__((counted_by (count))); }; 2. Later, if the argument of the this attribute need to be extended to an expression, we might need to extend the C FE to accept ".count” in the future. Let me know if you have further comments and suggestions. thanks. Qing > On Jun 20, 2023, at 3:40 PM, Qing Zhao via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > >> On Jun 16, 2023, at 5:35 PM, Joseph Myers <jos...@codesourcery.com> wrote: >> >> On Fri, 16 Jun 2023, Qing Zhao via Gcc-patches wrote: >> >>>> So for >>>> >>>> struct foo { int c; int buf[(struct { int d; }){ .d = .c }]; }; >>>> >>>> one knows during parsing that the .d is a designator >>>> and that .c is not. >>> >>> Therefore, the above should be invalid based on this rule since .c is >>> not a member in the current structure. >> >> What do you mean by "current structure"? I think two different concepts >> are being conflated: the structure *being initialized* (what the C >> standard calls the "current object" for a brace-enclosed initializer >> list), > > I think the concept of “current structure” should be stick to this. > >> and the structure *being defined*. > Not this. > > (Forgive me about my poor English -:)). > > Then it will be cleaner? > > What’s your opinion? > > >> The former is what's relevant >> for designators. The latter is what's relevant for the suggested new >> syntax. And .c *is* a member of the structure being defined in this >> example. >> >> Those two structure types are always different, except for corner cases >> with C2x tag compatibility (where an object of structure type might be >> initialized in the middle of a redefinition of that type). > > Can you give an example on this? Thanks. > > Qing >> >> -- >> Joseph S. Myers >> jos...@codesourcery.com