Paul Grenyer wrote:
> > No, C and C++ evaluate parameters right to left.
> Actually, Phil, I think you'll find the order of evalutation is not
> specified by either standard, so a vendor is free to do it in
> whatever order they want.
In practice, though, you'll find it is right to left on x86 using the normal
calling conventions. Since all parameters are passed on the stack and the
stack pointer decreases, they have to be placed on the stack right to left
so they end up the right-way round relative to the new function's stack
frame, i.e.
more stack> <local vars> <frame ptr> <return addr> <arg1> <arg2> ...
esp ebp
Presumably this is so that the function can always access the first argument
from the frame pointer without knowing how large the argument list really
is, and the list can carry on indefinitely up the stack for varargs
functions.
That said you certainly shouldn't rely on it. In any case I prefer to avoid
*any* side effects in argument lists (or if tests) where I can.
Rup.