[Top][All Lists]

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

Re: Arithmetic expression: evaluation order bug

From: Steffen Nurpmeso
Subject: Re: Arithmetic expression: evaluation order bug
Date: Thu, 29 Dec 2022 18:46:46 +0100
User-agent: s-nail v14.9.24-383-g2889cb06b9

Alain D D Williams wrote in
 |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 \
 |At most there should be a note in the documentation that this sort of thing
 |leads to undefined behaviour -- that is what happens in other languages.
 |This is very much not a bug in bash.

I very much disagree.  My mailer's $(()) evaluator also does this
right.  (And busybox's one, if it gets accepted.)

 |C does it differently. I would not be surprised to see different C \
 |produce different results or different results with different levels of

Come on.  Be a brave man.

|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

reply via email to

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