Re: [fpc-pascal] Illegal counter variable?

2019-09-10 Thread Ralf Quint

On 9/10/2019 4:26 PM, wkitt...@windstream.net wrote:

On 9/9/19 10:11 AM, James Richters wrote:

Pascal doesn't have things like step...


hunh??? i don't think that's right but i'm just catching up after 
several 10+ hours days of $job...


i know that i've written code in the past that did use something to 
step X numbers per run through the look and it did not involved 
manually incrementing the loop var...



I am not aware of any Pascal implementation that does have a STEP 
parameter for FOR loops, and I am programming in Pascal at least as long 
as you... ;-)


The closest would be the FOR..IN variant, which works in Delphi (D2006? 
and later) and is AFAIK supported in FPC by now. But that would be 
iterating over a set, not increment an integer/cardinal variable in an 
increment other than 1...


Ralf

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


Re: [fpc-pascal] Illegal counter variable?

2019-09-10 Thread wkitty42

On 9/9/19 10:11 AM, James Richters wrote:

Pascal doesn't have things like step...


hunh??? i don't think that's right but i'm just catching up after several 10+ 
hours days of $job...


i know that i've written code in the past that did use something to step X 
numbers per run through the look and it did not involved manually incrementing 
the loop var...



--
 NOTE: No off-list assistance is given without prior approval.
   *Please keep mailing list traffic on the list unless*
   *a signed and pre-paid contract is in effect with us.*
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Illegal counter variable?

2019-09-10 Thread James Richters
I’m trying to use it in a way that always worked in Turbo Pascal for DOS, I 
have no idea how to program in C,  I find Pascal much more clear and easy to 
follow and C just confuses me, so I never spent much time other than a few 
stray projects here and there on C…  I’ve always used pascal since the 80s, and 
in fact my units that change the for loop variable that run in {$Mode TP} are 
the original code from turbo pascal written in the 80s.. over the decades I’ve 
modified stuff all around it, but the actual code with for loops with changing 
control variables is the exact same code I was running on old 4.7MHz Dos 
machines with turbo pascal for DOS…  so for nearly 40 years I have never even 
known there was some rule against changing the control variable in for loops,  
it’s always worked and I’ve always used it.. and it still works if I use {$Mode 
TP}  it may not work if I try to use Delphi or something else, and there may be 
some pascal version even older than turbo pascal for DOS that didn’t act this 
way, but from the entire scope of my programming experience, this is something 
that has just always worked and I never had a reason not to use it.

 

James

 

From: fpc-pascal  On Behalf Of Markus 
Greim
Sent: Monday, September 9, 2019 1:32 PM
To: FPC-Pascal users discussions 
Subject: Re: [fpc-pascal] Illegal counter variable?

 

James, 

 

not every body is using a GHz machine. I am , for example, programming a 80186 
in an embedded system with very limited speed an RAM. 

But I understand thats not a general argument. 

 

But look at MISRA C. Its a big set of rules for "real" save C programming, more 
or less now the standard in the automobile industry. 

Also here are strict rules for counters in for loops. 

See: 

https://www.misra.org.uk/forum/viewtopic.php?t=272​

 

So what they are doing is writing Pascal programs in C... ;-) And they need 
huge and expensive and complex  tools to check the C code for 

MISRA compatibility!

So we should NOT give up the safety of Pascal for the sloppiness of C! 

 

Kind Regards

 

Markus

  

 



On September 9, 2019, 7:19 PM GMT+2 ja...@productionautomation.net 
  wrote:

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 mailto:fpc-pascal-boun...@lists.freepascal.org> > On Behalf Of Bernd Oppolzer
Sent: Monday, September 9, 2019 10:46 AM
To: FPC-Pascal users discussions mailto: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 

Re: [fpc-pascal] Illegal counter variable?

2019-09-10 Thread Markus Greim
James, 



not every body is using a GHz machine. I am , for example, programming a 80186 
in an embedded system with very limited speed an RAM. 

But I understand thats not a general argument. 



But look at MISRA C. Its a big set of rules for "real" save C programming, more 
or less now the standard in the automobile industry. 

Also here are strict rules for counters in for loops. 

See: 

https://www.misra.org.uk/forum/viewtopic.php?t=272​


So what they are doing is writing Pascal programs in C... ;-) And they need 
huge and expensive and complex tools to check the C code for 

MISRA compatibility!
So we should NOT give up the safety of Pascal for the sloppiness of C! 

Kind Regards


Markus

--- original message ---
On September 9, 2019, 7:19 PM GMT+2 ja...@productionautomation.net wrote:

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  On Behalf Of Bernd 
Oppolzer
Sent: Monday, September 9, 2019 10:46 AM
To: FPC-Pascal users discussions 
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
--- end of original message ---___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Illegal counter variable?

2019-09-10 Thread Markus Greim
AFAIK these is the standard behavior since the first PASCAL versions. 

We must not change it. It prevents a lot of side effects, and PASCAL is NOT C 
without brackets!
Use while or repeat instead!



>From Niklaus Wirths last 2004 Oberon manual: 

https://people.inf.ethz.ch/wirth/ProgInOberon2004.pdf​




t "It is recommended that the for statement be used in simple cases only; in 
particular, no 
components of the expressions determining the range must be affected by the 
repeated 
statements, and, above all, the control variable itself must not be changed by 
the repeated 
statements. The value of the control variable must be considered as undefined 
after the for 
statement is terminated."

Kind Regards


Markus

--- original message ---
On September 9, 2019, 5:20 PM GMT+2 mar...@templot.com wrote:

On 09/09/2019 15:11, James Richters wrote:

>> If (I>86) And (I<95) then Continue;

>> What does continue do exactly? Loop back to the beginning of the for loop 
>> right away?


> Hi James,


> Yes in effect -- it jumps forward to the test at the end of a loop. Very 

> useful.


> See: https://www.freepascal.org/docs-html/rtl/system/continue.html


> cheers,


> Martin.

> ___

> fpc-pascal maillist - fpc-pascal@lists.freepascal.org

> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
--- end of original message ---___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal