<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Still, the theory's there just in case... if the arguments are
constant (but unknown) and the pure function is called multiple
times, then it can be optimised to only be called once.<br>
</p>
<p>Gareth aka. Kit<br>
</p>
<div class="moz-cite-prefix">On 06/06/2019 01:08, J. Gareth Moreton
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:2d12ece5-c53e-b195-ae35-7cb47b43ad5f@moreton-family.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Ah, fair enough. I didn't think to study the for-loop that
closely yet since I haven't really found a need to check its
code. Sometimes I feel silly blurting out my ideas like this,
but at least you stopped me from doing a fool's errand. Thanks.</p>
<p>Gareth aka. Kit<br>
</p>
<div class="moz-cite-prefix">On 05/06/2019 22:38, Sven Barth via
fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFMUeB9SfiWAHTkNDK62D8z3cSQPn=wFrYLrrLWTxmKf7LaB_g@mail.gmail.com">
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">
<div dir="auto">
<div class="gmail_quote" dir="auto">
<div dir="ltr" class="gmail_attr">J. Gareth Moreton <<a
href="mailto:gareth@moreton-family.com"
moz-do-not-send="true">gareth@moreton-family.com</a>>
schrieb am Mi., 5. Juni 2019, 18:06:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<p><tt><b>for </b>X := 0 <b>to </b>Min(BUFFER_SIZE,
DataLeft) <b>- 1 do</b></tt><tt><br>
</tt><b><tt>begin</tt></b><tt><br>
</tt><tt> { Do some work that doesn't modify DataLeft
}</tt><tt><br>
</tt><tt><b>end</b>;</tt></p>
<p>Say that Min is given the <b>pure </b>directive,
BUFFER_SIZE is a <b>const </b>and DataLeft is a
property or some non-local variable. Since no
volatile intrinsic is used to safeguard
multi-threading issues, and DataLeft isn't modified by
the for-loop, DataLeft can be promoted to the stack or
a register. Even though its exact value is not known,
DataLeft is determined to be constant within the
confines of the for-loop, hence since both arguments
in "Min(BUFFER_SIZE, DataLeft)" are constants, the
result must also be constant, since it's a pure
function, therefore the function only has to be called
once and its result be stored on the stack, recalled
during each iteration of the for-loop. At least
that's the theory. Of course, you can just store the
result yourself in a local variable and use that as
part of the for-loop, but it's just a thought where
pure functions could be used that doesn't involve
computing their result at compile-time. </p>
</div>
</blockquote>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">With properties or global variables you can't
guarantee that DataLeft is constant as the for loop might
call some routine that more or less indirectly might change
what DataLeft returns. </div>
<div dir="auto">That said: the end-expression of a for-loop is
specified to be evaluated only once anyway (in contrast to
C-like languages). </div>
<div dir="auto"><br>
</div>
<div dir="auto">Regards, </div>
<div dir="auto">Sven </div>
<div class="gmail_quote" dir="auto">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex"> </blockquote>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org" moz-do-not-send="true">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel" moz-do-not-send="true">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top: 1px solid #D3D4DE;">
<tbody>
<tr>
<td style="width: 55px; padding-top: 13px;"><a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient"
target="_blank" moz-do-not-send="true"><img
src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif"
alt="" style="width: 46px; height: 29px;"
moz-do-not-send="true" width="46" height="29"></a></td>
<td style="width: 470px; padding-top: 12px; color:
#41424e; font-size: 13px; font-family: Arial, Helvetica,
sans-serif; line-height: 18px;">Virus-free. <a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient"
target="_blank" style="color: #4453ea;"
moz-do-not-send="true">www.avast.com</a> </td>
</tr>
</tbody>
</table>
<a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1"
height="1" moz-do-not-send="true"> </a></div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
</body>
</html>