Am Montag, dem 07.04.2025 um 14:44 +0200 schrieb Michael Matz:
> Hello,
> 
> On Sat, 5 Apr 2025, Bill Wendling wrote:
> 
> > > > > > So, a different attribute name “counted_by_exp” might be better?
> > > > > 
> > > > > I would prefer Martins empty-decl idea to that: "counted_by(;len+0)"
> > > > > (looks up 'len' normally, i.e. doesn't look into current struct).  It
> > > > > would naturally fit the either decl+expr or lone-ident parse.
> > > > > It may look weird but empty declarations are okayish IMHO.
> > > > > 
> > > > > But overall: I just don't know, it all looks a bit unsexy, there only
> > > seem
> > > > > to be rocks and hard places :)
> > > > 
> > > > I would not worry about this case too much, because I do expect this
> > > > to be a common use case anyway.  That it looks strange may even be
> > > > an advantage here, as it alerts the reader that this is unusual.
> > > 
> > > This is an interesting point and also a good point. -:)
> > > 
> > > The other thought that bother me a little bit is:
> > > 
> > > For the same attribute, counted_by, is it strange to have two different
> > > looking up rules
> > > depending on the different number of arguments?l
> > > 
> > 
> > Sorry for the HTML. On my phone.
> > 
> > I think adding a ';' isn't the best option. It's too easy to overlook when
> > reading the attribute and forget when writing the attribute.  Using a
> > separate attribute name is much cleaner, IMO. Then again, I've been wrong
> > before. :-)
> 
> So, what specifically would the two attributes do different?  FWIW: what 
> worries me about accepting a generic expression in counted_by, that isn't 
> prefixed by a (possibly empty) decl, is that after seeing a non-type 
> identifier the parser doesn't yet know if it's the lone-ident case (look 
> up in struct scope) or the expression case (look up everything in global 
> scope).  It requires look-ahead to decide this.
> 
> Would that be the difference between the attributes?  One accepting _only_ 
> a lone-ident or the decl+expr syntax, and the other _only_ expressions 
> that are never looked up in struct-scope (not even if its lone-ident)?

My understanding is that one accepts only a lone identifier and nothing
else, i.e.

counted_by(identifier)

and the other only accepts expressions, possibly including a forward
declaration.

counted_by_expr(expression)
counted_by_expr(decl; expression)


And

counted_by_expr(size_t id; id)

would be equivalent to

counted_by(id)

when the struct has a member "id" with type size_t.

Martin


Reply via email to