On Thu, Dec 29, 2022 at 09:09:25PM +0100, Emanuele Torre wrote: > On Thu, Dec 29, 2022 at 05:35:48PM +0000, Alain D D Williams wrote: > > On Thu, Dec 29, 2022 at 06:23:09PM +0100, Steffen Nurpmeso wrote: > > > Hello. > > > > > > Name: bash > > > Path: /usr/ports/core > > > Version: 5.2.15 > > > Release: 1 > > > > > > $ i=10 j=20;echo $(( i += j += i += j ));echo $i,$j > > > 60 > > > 60,50 > > > $ i=10 j=20;echo $(( i += j += i += i ));echo $i,$j > > > 50 > > > 50,40 > > > > You are modifying something that is used elsewhere in an expression. I am > > not > > surprised that you do not get what you expect; others might expect something > > different. > > I don't think that is correct. > > Unlike a++ - --a which is unspecified in C because the order of > evaluation of the lhs and rhs of the - operator is unspecified, the > order of evaluation of i += j += i += i or i += (j += (i += i)) is > well defined and in no way ambiguous.
No. i += j += i += i does not contain a sequence point so there is no guarantee that anything is completed (eg storing a value in variable i) before another part (getting a value from variable i) is evaluated. https://stackoverflow.com/questions/3575350/sequence-points-in-c https://c-faq.com/expr/seqpoints.html -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 https://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: https://www.phcomp.co.uk/Contact.html #include <std_disclaimer.h>