b=[a]=({3});
seems to be of the type:
foo=bar=baz;
but [a] can't stand by itself
Yes it can. When it is an lvalue. The semantics is that a is assigned the first element of the array. The more general syntax is
[a,b,c] = expr
which assigns the three elements in the array produces by expr to the three variables a, b and c. The value of the assignment expression is the entire array.
yet, the fact that this assigns ({3}) to b seems to be unrelated to the [a] inbetween.
Yes. That is always the case with chained assignments.
i would even argue that this is a bug, because a is not affected by nor has it any effect on the assignment.
But a is affected. It's set to 3.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2002-11-12 12:48: Subject: Re: More about ADTs
On Tue, Nov 12, 2002 at 12:15:04PM +0100, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
Sorry, that syntax already has semantics:
which are?
int a; array(int) b; b=[a]=({3});
(1) Result: ({ /* 1 element */ 3 })
this example is not very conclusive,
b=[a]=({3});
seems to be of the type:
foo=bar=baz;
but [a] can't stand by itself yet, the fact that this assigns ({3}) to b seems to be unrelated to the [a] inbetween.
i would even argue that this is a bug, because a is not affected by nor has it any effect on the assignment.
so what is the semantics of allowing this statement?
greetings, martin.
/ Brevbäraren