[fpc-pascal] Arrays in debugger; No range errors on arrays

Lance Boyle lanceboyle at cwazy.co.uk
Tue May 24 13:58:55 CEST 2005


Hi list,

I'm playing with FPC 2.0.0 on OS X 10.3.9 using Xcode 1.5. I run the 
following little program...


program dumpmePascal;
    uses
      EmptyPlaceHolderUnit;

    var
       i : integer;
       topArray : array[10..13] of real;
       {debugger doesn't show this array at all--discussed previously
       on this list}

begin
    for i := 10 to 13 do     {OK}
       topArray[i] := sqr(i);
    for i := 10 to 13 do     {OK}
       writeln(topArray[i]);

    for i := 20 to 23 do     {OK too! No range error reported.}
       topArray[i] := sqr(i);
    for i := 20 to 23 do     {prints correct squares}
       writeln(topArray[i]);

    printstuff;
end.



unit EmptyPlaceHolderUnit;
interface
     procedure printstuff;

implementation

     procedure printstuff;
         var
         j : longint;
         anArray      : array[1..4] of real;
         {debuger shows anArray as 0..3, with incorrect value for 
"anArray[0]"}
         anotherArray : array[21..24] of real;
         {debuger shows anotherArray as 0..3, with incorrect value for 
all}
     begin
         for j := 1 to 4 do
             anArray[j] := 3 * j;
         for j := 1 to 4 do
             writeln(anArray[j]);

         anArray[205] := 12345.6789;     {No range error reported}
         writeln(anArray[205]);          {No range error reported}
         {Trying to write to anArray[206 and higher causes}
         {runtime error 216.}

         for j := 21 to 24 do            {OK}
             anotherArray[j] := 2 * j;
         for j := 21 to 24 do            {OK}
             writeln(anotherArray[j]);

         for j := 31 to 34 do
             anotherArray[j] := 2 * j;   {No range error reported}

         for j := 41 to 44 do
             writeln(anotherArray[j]);   {No range error reported}
     end;

end.


...and  get the following output:

[Session started at 2005-05-24 04:55:42 -0700.]
  1.00000000000000E+002
  1.21000000000000E+002
  1.44000000000000E+002
  1.69000000000000E+002
  4.00000000000000E+002
  4.41000000000000E+002
  4.84000000000000E+002
  5.29000000000000E+002
  3.00000000000000E+000
  6.00000000000000E+000
  9.00000000000000E+000
  1.20000000000000E+001
  1.23456789000000E+004
  4.20000000000000E+001
  4.40000000000000E+001
  4.60000000000000E+001
  4.80000000000000E+001
  0.00000000000000E+000
  4.94065645841247E-324
-4.28882459806687E-232
-3.51094486606932E-232

Executable “dumpmePascal” has exited with status 0.


As I've indicated in some of the comments, there appears to be some 
range checking issues--is range checking off by default?

A second issue is that arrays that begin with any index other than 0 
seem to be displayed incorrectly in the debugger window of Xcode.

Jerry




More information about the fpc-pascal mailing list