[fpc-devel] Standard generic classes
J. Gareth Moreton
gareth at moreton-family.com
Thu Jun 6 02:08:12 CEST 2019
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.
Gareth aka. Kit
On 05/06/2019 22:38, Sven Barth via fpc-devel wrote:
> J. Gareth Moreton <gareth at moreton-family.com
> <mailto:gareth at moreton-family.com>> schrieb am Mi., 5. Juni 2019, 18:06:
>
>
> *for *X := 0 *to *Min(BUFFER_SIZE, DataLeft) *- 1 do*
> *begin*
> { Do some work that doesn't modify DataLeft }
> *end*;
>
> Say that Min is given the *pure *directive, BUFFER_SIZE is a
> *const *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.
>
>
> 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.
> That said: the end-expression of a for-loop is specified to be
> evaluated only once anyway (in contrast to C-like languages).
>
> Regards,
> Sven
>
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190606/27a8452b/attachment.html>
More information about the fpc-devel
mailing list