<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"
xmlns:ns0="urn:schemas-microsoft-com:office:smarttags">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body bgcolor=white lang=EN-NZ link=blue vlink=purple>

<div class=Section1>

<div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'>Hi Stacey,</span><span style='font-size:12.0pt;
font-family:"Times New Roman","serif"'><o:p></o:p></span></p>

</div>

</div>

<blockquote style='border:none;border-left:solid black 1.5pt;padding:0cm 0cm 0cm 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'>

<div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'>----- Original Message ----- <o:p></o:p></span></p>

</div>

</div>

<div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt;background:#E4E4E4'>

<p class=MsoNormal style='background:#E4E4E4;border:none;padding:0cm'><b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> <a
href="mailto:stacey@cjntech.co.nz" title="stacey@cjntech.co.nz">Stacey Verner</a>
<o:p></o:p></span></p>

</div>

</div>

<div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><b><span style='font-size:
10.0pt;font-family:"Arial","sans-serif"'>To:</span></b><span style='font-size:
10.0pt;font-family:"Arial","sans-serif"'> <a href="mailto:delphi@ns3.123.co.nz"
title="delphi@ns3.123.co.nz">NZ Borland Developers Group - Delphi List</a> <o:p></o:p></span></p>

</div>

</div>

<div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><b><span style='font-size:
10.0pt;font-family:"Arial","sans-serif"'>Sent:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> Friday, February 16,
2007 11:34 AM<o:p></o:p></span></p>

</div>

</div>

<div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><b><span style='font-size:
10.0pt;font-family:"Arial","sans-serif"'>Subject:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> [DUG] Delphi Calling
Convetion is Weird!!<o:p></o:p></span></p>

</div>

</div>

<div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span style='font-size:12.0pt;
font-family:"Times New Roman","serif"'><o:p>&nbsp;</o:p></span></p>

</div>

</div>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>After an odd bug and
a bit of testing I have found that the parameters in Delphi (tested 6 and 2006)
are evaluated very strangely.<o:p></o:p></span></p>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>The 3<sup>rd</sup>
parameter is evaluated first followed by 4, 5, 6 etc and then the 2<sup>nd</sup>
and then the 1<sup>st</sup>.</span><o:p></o:p></p>

</div>

</blockquote>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Always this order? Or
does it vary sometimes if there are a different number of parameters? or if the
mix of parameters varies, ie between static values, in-line expressions,
function invocations?<o:p></o:p></span></p>

</div>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>Yep. Always this order. I just
tried it with 2, 3, 4, 5, 6, 7, 8 and 9 parameters and the results were as
follows:<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>2 parameters: 2, 1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>3 parameters: 3, 2, 1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>4 parameters: 3, 4, 2, 1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>5 parameters: 3, 4, 5, 2, 1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>6 parameters: 3, 4, 5, 6, 2, 1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>7 parameters: 3, 4, 5, 6, 7, 2,
1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>8 parameters: 3, 4, 5, 6, 7, 8,
2, 1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>9 parameters: 3, 4, 5, 6, 7, 8,
9, 2, 1<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<blockquote style='border:none;border-left:solid black 1.5pt;padding:0cm 0cm 0cm 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>This appears to be
because the default calling convention is <b>register</b> which (from the
documentation) puts up to 3 parameters in registers and the rest on the stack.
It seems to process the stack ones first from parameters 3 onwards (Why 3?
Shouldn&#8217;t it be 4 if we are putting 3 into registers. Must be only
putting 2 in the registers), and then the first 2 in reverse order into the
registers. </span><o:p></o:p></p>

</div>

</blockquote>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>It may be that the
two registers it uses for parameters 1 and 2 are also used in calculating
parameter addresses in any call; or used in evaluating expressions in
parameters;&nbsp;if so, parameters 1 and 2 can't be set into the registers
until all the rest of the parameters have been evaluated.&nbsp;Also, registers
containing parameters of the main function can't be set before calling any
functions in the parameters, if they will be used for parameters of those
functions.</span><o:p></o:p></p>

</div>

<blockquote style='border:none;border-left:solid black 1.5pt;padding:0cm 0cm 0cm 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>The documentation
also says that is supposed to pass the from left to right, but it obviously
doesn&#8217;t.</span><o:p></o:p></p>

</div>

</blockquote>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Do you mean the order
in which parameter expressions are evaluated? Yes, if that's defined, the
compiler should respect it. Or the documentation should be changed to included
a caveat about the possible results of the compiler's optimisation.</span><o:p></o:p></p>

<p class=MsoNormal style='border:none;padding:0cm'>&nbsp;<o:p></o:p></p>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>You'd be safest to
call your functions and save their results in temporary variables which you
then pass to the main function. That way you can control the order of the side
effects yourself and it'll work whatever the compiler does.<o:p></o:p></span></p>

</div>

<p class=MsoNormal><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'>Yes. Using temporary variables
are the best bet, and it&#8217;s usually clearer anyway.<o:p></o:p></span></p>

<p class=MsoNormal>&nbsp;&nbsp;<o:p></o:p></p>

<div style='mso-element:para-border-div;border:none;border-left:solid windowtext 1.0pt;
padding:0cm 0cm 0cm 4.0pt'>

<p class=MsoNormal style='border:none;padding:0cm'><span lang=EN-US
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Brian</span><o:p></o:p></p>

</div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

<p class=MsoNormal><span style='color:#1F497D'>Stacey<o:p></o:p></span></p>

</div>

</body>

</html>