<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">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"></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>