Am Freitag, dem 24.01.2025 um 14:23 +0000 schrieb Joseph Myers: > On Thu, 23 Jan 2025, Martin Uecker wrote: > > > I can see why it could be seen in this way. But the designator > > syntax could also be seen (more or less) as a tiny subset of > > the expression syntax allowing only assignments. It is just > > Initializers are not assignments. They should not be confused with > assignments. They are valid in contexts where assignments are not > (initializers evaluated at translation time, with correspondingly > different semantics compared to evaluating those expressions at runtime; > initialization of atomic objects in cases where assignment to an element > would have undefined behavior). The semantics are not always the same as > default initialization followed by a sequence of assignments.
No doubt, but this is a semantic difference which does necessarily imply that the syntax has to be different. The syntax of initialization seems intentionally designed to look like assignment to be intuitive. The "=" in designators otherwise seems to serve no useful purpose. > As I understand it, C++ doesn't allow designated initializers out of order, > which means that any attempt to apply C++ initialization semantics to C is > problematic. > > > Using __self__ would also > > > > struct { int a[10]; } x = { __self__.a[INDEX] = 1 }; > > > > work here, but is more verbose. > > That would be fundamentally different. __self__.a[INDEX] = 1 would be an > assignment expression, with the result of that assignment then being used > itself as an initializer (undesignated, so for x.a[0]). I understand your proposal where the use of __self__ would imply that it is an expression and not a designator and thereby allows the parser to distinguish between both without relying on semantic information. My point was that this syntax, i.e. using __self__ instead of only using a dot could have made sense for designators just as well. Or in other words, there is no logical reason why designators have no __self__ while counted_by would have it, except to be able to distinguish between them purely based on syntax. But the parser can already distinguish between those cases by using semantic information, so this is not needed if one does not insist on context-freeness in this case (which we do not have anyway). So in my opinion, the __self__ is not needed. Martin