John Ollason wrote:
I think that the following program ought to produce a run-time error but it doesn't. I have had a look at the GPC manual but I can't find any compiler directive that says Check array bounds,
... snip ...
Version 2.95.2 19991024 (release), running under RedHat 6.1, Cartman. Yes, I know it's old, but my version of VMWare won't work on the later kernels.
program arraytest(output); var i:integer; a,b:array[1..5] of integer; begin for i:=1 to 5 do a[i]:=i; for i:=1 to 10 do b[i]:=a[i]; for i:=1 to 20 do writeln(i,' ',b[i]); end.
This has to do with the lack of bounds checking in gpc, so far. However you are not giving your code the best change of detecting problems. Note the minor revision below:
PROGRAM arraytest(output); CONST alimit = 5; TYPE aix = 1..alimit; VAR i : aix; a, b : ARRAY[aix] OF integer; BEGIN FOR i := 1 TO alimit DO a[i] := i; FOR i := 1 TO 10 DO b[i] := a[i]; FOR i := 1 TO 20 DO writeln(i, ' ', b[i]); END.