Jerald Fijerald <jf*@freemail.gr> scribbled the following:
Hi all.
I was wondering if this expression is ok and has not any undefined
behaviors (bad style is not an issue):
int x;
x = a [i] > 0 ? a [i++] : 1000;
I believe it is ok because in the case
x ? i++ : 0;
'i' is not incremented if x==0.
So it is ok, yes?
This is completely OK, safe, kosher and hunky-dory. The ?: operator
constitutes a sequence point, so a[i]>0 is guaranteed to have fully
evaluated before either a[i++] or 1000 can begin evaluating.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\--
http://www.helsinki.fi/~palaste --------------------- rules! --------/
"No, Maggie, not Aztec, Olmec! Ol-mec!"
- Lisa Simpson