bug-bash
[Top][All Lists]
Advanced

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

Re: Arithmetic expression: evaluation order bug


From: Emanuele Torre
Subject: Re: Arithmetic expression: evaluation order bug
Date: Thu, 29 Dec 2022 21:09:25 +0100
User-agent: Mutt/2.2.9 (2022-11-12)

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.

 emanuele6



reply via email to

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