[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Arithmetic assignment side-effects
From: |
Dan Douglas |
Subject: |
Arithmetic assignment side-effects |
Date: |
Sat, 03 Aug 2013 17:04:41 -0500 |
User-agent: |
KMail/4.10.5 (Linux/3.10.1-pf+; KDE/4.10.5; x86_64; ; ) |
Is it specified what the value of x should be after this expression?
x=0; : $((x+=x=1))
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.
<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
- Arithmetic assignment side-effects,
Dan Douglas <=