On 18.05.2018 13:28, Marco van de Voort wrote:
In our previous episode, Mattias Gaertner said:
ISO7185: "After a for-statement is executed, other than being left by a 
goto-statement, the
control-variable shall be undefined"

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Declarations_and_Statements_(Delphi)#For_Statements:
"After the for statement terminates (provided this was not forced by a Break or 
an Exit procedure),
the value of counter is undefined."

So this shall not be unrolled, but is still error prone, if Result is not set 
after the regular end of the for loop.
To avoid misunderstandings:
The above clearly says, that using break/goto/exit is safe:

Well, well, clearly. One could interpret it that it says that the for
statement terminates naturally if not forced by break or exit.  It doesn't
say what happens with break or exit.

Sometimes I feel that FPC developers are more lawyers than programmers.

The fact that this exception is not documented with an example makes it very
ambiguous IMHO.

Your very own documentation isn't ambiguous at all, though: https://www.freepascal.org/docs-html/ref/refsu58.html#x164-18600013.2.4 [^]

Citation: "If the loop was terminated prematurely with an exception or a break statement, the loop variable retains the value it had when the loop was exited."

Ondrej
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to