Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-12

Is this behavior related to calling convention?

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

I have this function:

function Compare(v1, v2: Integer): Integer;

And called like this:

Result := Compare(stack.Pop, stack.Pop);

The behavior is that the second Pop is evaluated first, thus reversed the meaning of the function.

Is it true that all parameter evaluation goes from right to left?

Thanks!
Xiangrong

Reply by email

Jonas Maebe
to Xiangrong Fang
Xiangrong Fang wrote
Is it true that all parameter evaluation goes from right to left?

The order in which parameters are evaluated is unrelated to the calling convention. This order has always been undefined in FPC, and it is also undefined in recent versions of Delphi.

Jonas

Reply by email

leledumbo
to Xiangrong Fang: I have this function: function Compare(v1, v2: Integer): Integer; And called like this:…

Nope, calling convention only specifies parameter passing order, not parameter evaluation order. If you want to specify exactly how the parameters are evaluated, put each in a local variable first, according to your order needs.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Is-this-behavior-related-to-calling-convention-tp5717622p5717624.html Sent from the Free Pascal - General mailing list .

Reply by email

Jürgen Hestermann
to Jonas Maebe: The order in which parameters are evaluated is unrelated to the calling convention. This…
Jonas Maebe wrote
The order in which parameters are evaluated is unrelated to the calling convention. This order has always been undefined in FPC, and it is also undefined in recent versions of Delphi.

I am wondering what the advantage is to *not* garantee a left to right order. I can't think of a situation where changing this order makes any sense.

Reply by email

Marco van de Voort
to Jürgen Hestermann

In our previous episode, J?rgen Hestermann said:

I am wondering what the advantage is to *not* garantee a left to right order.

Undefined order allows to do the evaluation that needs the most temps first I guess, which reduces spilling.

Reply by email