oz****@bigpond.com (ozbear) writes:
On Sat, 03 Nov 2007 03:34:58 +0000, Ben Bacarisse
<be********@bsb.me.ukwrote:
>>James Harris <ja************@googlemail.comwrites:
>>On 30 Oct, 20:10, Keith Thompson <ks...@mib.orgwrote:
...
Consider how the return statement is defined: the expression is
evaluated, and the result is returned. Updating ``a'' is part of the
evaluation of the expression.
Is there some particular reason you're concerned that a compiler might
handle something this simple incorrectly?
In any context other than a return statement
mov eax, a
{use eax}
inc eax
Not quite "any". In a function call, f(a++) the side-effects must
have happened by the time function is entered. Of course, if the "use
it" is "push it" and the function call follows the inc (and another
mov) we are OK, but the same could also be done for the return (the
"use it" being put into register used for return values).
<snip>
I am not quite sure I understand what you are saying. While a
sequence point does occur just before and after the function call, the
value of /a/ passed will be its pre-incremented value.
Yes. I was making a very small point. The discussion was about how
likely it is that 'return a++;' will be miss-compiled. James Harris
pointed out that "in any context other than return" the compiler can
load the value of a, generate the code that uses it, then emit an
increment instruction. I was just pointing out that 'f(a++);' is
similar -- the code that uses 'a' gets the prior value but the
increment must have happened before any of that code is executed.
--
Ben.