[fpc-pascal] Illegal counter variable?

Bernd Oppolzer bernd.oppolzer at t-online.de
Mon Sep 9 16:46:21 CEST 2019


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



More information about the fpc-pascal mailing list