[fpc-devel] FPC Delphi compatibility question...

Bruce Tulloch bruce at causal.com
Fri Jun 19 06:45:10 CEST 2009


I found what appears to a subtle difference between the Delphi & Kylix3
handling of dynamic array assignment and FPC in Delphi mode. If an
assignment is made along the lines:

type
    TArray : array of Integer;

var
    A, B : TArray;
    I : Integer;

type
    function F ( C : TArray ) : TArray;
    begin
       { does nothing }
    end

begin
    SetLength(B,4);
    for I := 0 to 3 do
       B[I] := I;

    A := Copy(B);
    A := F(B); { what is the correct answer here? }
end;

a question arises as to the value of A. Should it be nil or should it be
a copy of B?

Delphi and Kylix assume that because the function F does not assign a
value to Result (ie, does not assign a return value) that the Lvalue
assigned from F remains unchanged.

FPC assigns nil to A which IMHO is correct, but not when run in "bug for
bug" Delphi compatibility mode.

Obviously F not assigning Result is a programming error, but
unfortunately it can be a common one in legacy code.

What do others think about this compatibility difference?

Should it be fixed or should (possibly large) legacy codebases be debugged?

Cheers, Bruce.



More information about the fpc-devel mailing list