On 6 Dec, 2006, at 17:21, Young, Michael wrote:
I /think/ that with -O0 the arguments are evaluated left to right.
However, neither the standards nor gcc make any guarantee about
argument evaluation order. Not now and not historically either. Any
code that relies on a particular order of evaluation is broken.
You've just been lucky (or not, depending on the point of view) up to
now. It is typical that such bugs are exposed when the optimization
level is changed, which is a good reason to test regularly with
both -
O0 and -O2.
True - the standard doesn't say anything about the order in which
parameter
values are passed/pushed on the stack. (BTW - even ABIs aren't
"standards",
but rather "conventions".) But it is absolutely necessary to know
(and be
able to explicitly define/control) this order if one is doing inter-
language
or cross-tool development; without knowing the stack frame, how can an
assembler routine call a routine developed in 'C' or vice versa?
I think you are confusing here two very different things:
1) argument evaluation order: this has nothing to do with the calling
convention (pascal, cdecl, register). It is unspecified. If you need
to control it, evaluate the arguements yourself before the function
call.
2) argument passing order: this is related to the calling convention.
The compiler certainly guarantees that the arguments are put on the
stack or loaded into registers in a specified order. gcc has the
attributes stdcall, cdecl, etc. to control this, like any other
compiler.