[fpc-pascal] Range checking in a for loop

leledumbo leledumbo_cool at yahoo.co.id
Mon Oct 25 10:06:16 CEST 2010


Consider the following program:

program test;

var
  a: array [1..3] of Integer;
  i: Integer;
begin
  for i := 1 to 4 do
    a[i] := i;
end.

The compiler will accept this code happily, despite the fact that there's an
out of bounds array index when i = 4.

Since the behavior of for loop in FPC (at least in non Delphi / TP mode) is
deterministic, it should be possible to check whether the index is out of
bounds or not. Isn't it? Or is there any situation where it's not?
-- 
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Range-checking-in-a-for-loop-tp3235085p3235085.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list