Tim Riker wrote:
depends on the compiler. The spec leaves it open. gcc
will
likely do "0 1 2" but any where:
0 <= first <= second <= third <= 2
are valid iirc.
undefined really does mean undefined. The compiler
could call printf with any three values it has lying
around and still be conforming.
The order of argument evaluation is explicitly left
unspecified so as to give the implementation more
freedom to optimise. There is no 1st,2nd,3rd -
the arguments might be evaluated from the middle
outwards or the outside inwards or whatever makes
sense. You cannot even assume that if you write
that line out twice, that the order of evaluation
will be the same the second time round. If the
printf is within a loop, the order of evaluation
might vary on each invocation. Optimisers do all
kinds of fun stuff!
Since the behaviour is undefined, anything can
happen. In practice the compiler won't turn
into a bowl of geraniums, but it could do something
far worse, and emit code that does whatever it is
that you might have expected. That way you think
you've written something reasonable only to find
that it all blows up horribly when the platform changes
or you get a new compiler or you update your
existing compiler or whatever. About the only thing
that is guaranteed is that, if you fall prey to
this problem, your QA org will miss the problem and
your customers will find it :-)
To top it all, you cannot even be sure what the
value of i will be after the call.
I think gcc 3.3 spots this kind of thing (and the
other common variant:
a[++i] = ++i;
Antonio
--
---------------
Antonio Carlini arcarlini at
iee.org