R
Robert Gamble
Barry said:Barry said:On 21 Jul 2005 09:23:50 GMT, "S.Tobias"
[...]
Personally, I've never been entirely convinced that
`i = f(++i)' is bulletproof. Yes, there's a sequence point
[snip]
The whole purpose of sequence points, I think, is to impose a
reasonable set of of restrictions on what optimizations a compiler is
allowed to perform. An optimizer *can* move a side effect across a
sequence point, but it's allowed to do so only if it doesn't destroy
the semantics of the program. The actual program needs to behave,
[snip]
As a programmer, I'll just avoid things like "i = f(++i);". If I were
implementing a compiler, I'd try to be conservative enough in my
optimizations so that "i = f(++i);" works as expected, even if I can
[snip]
I think there's a worse pit-fall:
int i=0;
a = f(i++);
Which element is being set?
I think this is unspecified (6.5.16#4), but the behaviour
is defined.
I don't think the behavior is defined. While i is being updated only
once, there is a second requirement that i be evaluated at most once
as part of the process. Here i is being evaluated twice.
That would mean that the expression "i = i + i"; is undefind as i is
evaluated more than once. The second requirement you speak of actually
I don't think the i on the left of the = operator is evaluated.
Neither do I. I do think that it is evaluated twice on the right-hand
side though.
Robert Gamble