EC-RED wrote 14 lines
When compiling the following program :
Var a : longWord;
Begin
for a:=1 to 4294967294 do Begin
Writeln(a);
End;
End.
I get the following error message: "Error : range check error while
evaluating constants" and not compiled.
How do I make a loop up to 4294967294?
What is the limit of a for loop ?
The compiler is currently hardcoded on 32 bit platforms to reject any constant for loop bounds smaller than low(longint) or greater than high(longint). I think that this is purely historical (the check at least predates the switch to svn), and that the maximally allowed upper bound should be changed to high(cardinal) on 32 bit platforms (on 64 bit platforms, there is no such limitation even today).
You can work around this behaviour by assigning the value 4294967294 to a variable and by using that variable as the upper bound instead.
On the other hand, the output of Kylix while compiling the program:
$ dcc tt.pp
Borland Delphi for Linux Version 14.5
Copyright (c) 1983,2002 Borland Software Corporation tt.pp(4) Hint: FOR or WHILE loop executes zero times - deleted tt.pp(2) Hint: Variable 'a' is declared but never used in 'PROGRAM' tt.pp(9)
10 lines, 0.00 seconds, 19788 bytes code, 3084 bytes data.
And indeed, when executing the program, nothing is written. So it appears to have a similar limit for some reason, although the result is different (and assigning the value to a variable and using that as an upper bound also makes it work).
Jonas