J
James Harris
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
So in a return statement
mov eax, a
ret
inc eax
which, of course, is wrong so the compiler should handle two special
cases:
1. return a++; where a is automatic
mov eax, a
ret
/* ignore the ++ */
2. return a++; where a persists
mov eax, a
mov ebx, eax
inc ebx
mov a, ebx
ret