octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefined compound chaining behavior


From: Hossein Sajjadi
Subject: Re: undefined compound chaining behavior
Date: Tue, 10 Jun 2014 08:09:40 +0330

accoring to the manual:
expr1 op= expr2
is evaluated as
expr1 = (expr1) op (expr2)

so the expression
a=1;
a+=(a+=4);

should be equivalent to
a=1;
a=a+(a=a+4);

but the firt expression results 10  and second results 6

in expression a+=(a+=4) this procedure should be followed if order of
evaluations to be left to right:
first "a" in LHS is evaluated , so its value (1) will be stored to be
used by the rest of the expression
In RHS "a" is evaluated and its value (1) is sums with 4 reults 5
5 sums with "a" in LHS then result will be 6

but Octave's behavior is similar to c++ that takes the address of LHS
variable first and then evaluate RHS expression



reply via email to

[Prev in Thread] Current Thread [Next in Thread]