Am Dienstag, dem 21.01.2025 um 21:15 +0100 schrieb Martin Uecker:
> Am Dienstag, dem 21.01.2025 um 19:45 +0000 schrieb Joseph Myers:
> > On Tue, 21 Jan 2025, Martin Uecker wrote:
> >
> > > Coudn't you use the rule that .len refers to the closest enclosing
> > > structure
> > > even without __self__ ? This would then also disambiguate between
> > > designators
> > > and other uses.
> >
> > Right now, an expression cannot start with '.', which provides the
> > disambiguation between designators and expressions as initializers.
>
> You could disambiguate directly after parsing the identifier, which
> does not seem overly problematic.
The bigger issue seems that if you forward reference a member, you
do not yet know its type. So whatever syntax we pick, general expressions
seem problematic anyway:
struct {
char *buf [[counted_by(2 * .n + 3)]];
unsigned int n;
};
Martin
>
> > Note
> > that for counted_by it's the closest enclosing *definition of a structure
> > type*. That's different from designators where the *type of an object
> > being initialized by a brace-enclosed initializer list* is what's
> > relevant.
>
> You would have to treat the members of the referenced structure
> type as in scope. But this does not seem too absurd, because
>
> counted_by ( (struct foo){ .len = 1 }.len ) )
>
> could also be written with an inline definition:
>
> counted_by ( (struct foo { int len; }){ .len = 1 }.len ) )
>
> and then it would be natural to think of "len" as being in scope
> inside the initializer.
>
>
> Martin
>
>