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.  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]).

-- 
Joseph S. Myers
josmy...@redhat.com

Reply via email to