[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
- Arithmetic assignment side-effects, Dan Douglas, 2013/08/03
- Re: [ast-users] Arithmetic assignment side-effects, Roland Mainz, 2013/08/03
- RE: [ast-users] Arithmetic assignment side-effects,
Janis Papanagnou <=
- Re: Arithmetic assignment side-effects, Chris Down, 2013/08/04
- Re: Arithmetic assignment side-effects, Andreas Schwab, 2013/08/04
- Re: Arithmetic assignment side-effects, Chris Down, 2013/08/04
- Re: Arithmetic assignment side-effects, Linda Walsh, 2013/08/04
- Re: Arithmetic assignment side-effects, Dan Douglas, 2013/08/05
- Re: Arithmetic assignment side-effects, Linda Walsh, 2013/08/05
- Re: Arithmetic assignment side-effects, Andreas Schwab, 2013/08/05
- Re: Arithmetic assignment side-effects, DJ Mills, 2013/08/05
- Re: Arithmetic assignment side-effects, DJ Mills, 2013/08/05
- Re: Arithmetic assignment side-effects, Andreas Schwab, 2013/08/06