Yes, today such limitations do seem too restrictive, I wonder if the reasons 
for the restrictions have become obsolete.  You would have to have a really 
slow computer with very limited resources to optimize loops to the point of 
reducing functionality like this, and the tendency with modern pc's is to have 
a larger library of much more powerful and more flexible tools, even if they 
are more complex and take more memory and resources.  For example Case 
statements used to only work with characters or integers,  but the modern 
version now also works with strings, very much added functionality for sure, 
but also would use more resources.... but we would all rather have the 
capability because even a raspberry pi is blazing fast and has ram to burn 
compared to our old 8086s  It seems silly to me that I can't so what I used to 
do with Turbo Pascal for DOS where I was limited to programs of a few hundred 
K, due to optimizations that just can't make much of a difference at all on 
modern computers.   I am happy that FPC has TP compatibility mode though!   
It's just I get to a point where I eventually can't cross units since I can't 
have a circular unit reference.  So I have to choose for any given unit.. do I 
want my old for loops and change the control variables, or do I want cool new 
case statements... etc..  it would be nice to have {$Mode 
everything_the_way_I_want_it}

Since the compiler knows I was trying to change the variable inside the for 
loop, could it not just compile in not quite as efficient code (TP MODE for 
loop) when it detects this, and use the more efficient optimized code when it 
detects that it is able to use it?

James

-----Original Message-----
From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> On Behalf Of Bernd 
Oppolzer
Sent: Monday, September 9, 2019 10:46 AM
To: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org>
Subject: Re: [fpc-pascal] Illegal counter variable?


Am 09.09.2019 um 16:11 schrieb James Richters:
> I just don't see why having the limitation, there is no technical 
> reason that the for loop couldn't change that I can see.. especially since it 
> works in TP mode.


The original reason why some Pascal implementations had this limitation:

for performance or optimization reasons, the loop control variable was 
transferred to a register at the beginning of the loop, and changing the 
variable (at its storage location) inside the loop simply had no effect, 
because the variable was not fetched from there again during loop execution.
Worse: maybe, to make read accesses to the loop control variable valid inside 
the loop, they are prepared by storing the control register value into the loop 
control variable, thus turning changes to the loop control variable useless.

Forbidding (write) accesses to the loop control variable allows for many 
aggressive optimization strategies around loops.

Maybe today such limitations seem too restrictive.

Kind regards

Bernd

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to