On 21.05.2018 20:43, Florian Klämpfl wrote:
What do you expect?
That it writes a sequence from 1 to 10 to console. Instead, it writes 10 times "-1431655766".
That it just works?
Please define what you understand with "it just works". (If you agree with me on the sequence from 1 to 10, my answer is yes.)
If yes, what about program LoopUnrollTest; procedure Test; var I: Integer; procedure Test2; begin Writeln(I); I:=1; end; begin for I := 1 to 10 do Test2; end; begin Test; end.
In this (your) case I don't expect anything - it is one of FPC's favorites "undefined behaviour" because as documented, it is not allowed to change the loop variable value within a for loop.
In my case (without the I:=1 assignment) I don't change the loop variable value - it is absolutely valid to read from it.
Ondrej _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel