bug-bash
[Top][All Lists]
Advanced

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

RE: [ast-users] Arithmetic assignment side-effects


From: Janis Papanagnou
Subject: RE: [ast-users] Arithmetic assignment side-effects
Date: Sun, 4 Aug 2013 00:23:55 +0200

> 
> Is it specified what the value of x should be after this expression?

Typically assignment cascades (including the op= variants) are
evaluated from right to left...

> 
> x=0; : $((x+=x=1))

...so this would produce 2.

> 
> Bash, ksh93, mksh, posh say 1. zsh, dash, busybox say 2. Clang and gcc both
> throw warnings about it, but both plus icc agree on 2.

Interesting. So it's good to better avoid such cascades in ksh.

Thanks for pointing that out!

Janis

> 
> <stdin>:1:42: warning: unsequenced modification and access to 'x' 
> [-Wunsequenced]
> int main() { int x=0; printf("%d\n", x+=x=1); return 0; }
>                                       ~~ ^
> 1 warning generated.
> 2
> -- 
> Dan Douglas
> _______________________________________________
> ast-users mailing list
> ast-users@lists.research.att.com
> http://lists.research.att.com/mailman/listinfo/ast-users
                                          

reply via email to

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