[fpc-pascal] Incorrect display of non-zero-indexed arrays in debugger

Lance Boyle lanceboyle at cwazy.co.uk
Sun Jan 30 12:08:53 CET 2005


OS X 10.3.7, XCode 1.5, FPC 1.9.6

Still learning FPC in XCode. Here is a little test unit:


unit EmptyPlaceHolderUnit;
interface
    procedure printstuff;
implementation
    procedure printstuff;
       var
          j : longint;
          anotherArray : array[11..14] of real;
       begin
       for j := 11 to 14 do
          anotherArray[j] := 2*j;
       for j := 11 to 14 do
          writeln(anotherArray[j]);
       end;
end.


When debugging this, the debugger incorrectly shows me anotherArray 
with indices 0..3, not 11..14. The writeln() goes ahead and produces 
the correct output, but the debugger shows nonsense for the array 
values, as though it is actually accessing some memory locations that 
might correspond to anotherArray[0] through anotherArray[3].

In a variation, if I declare anotherArray[1..4] of real, the debugger, 
as above, shows me anotherArray[0..3], but when the assignment is made 
to anotherArray[1], the debugger indicates the correct value for 
anotherArray[1], while anotherArray[0] still shows garbage. Likewise 
for anotherArray[2..3], but who knows what the debugger thinks happens 
on assigning to anotherArray[4].

Perhaps the debugger assumes zero-based array indexing and then (with 
this false assumption), tries to display those values as if the array 
really does start with zero, in the process accessing incorrect memory 
locations. Is this a C disease?

Jerry





More information about the fpc-pascal mailing list