Hi, I have some code (very important for next version of
Generics.Collections):
------ code ------
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
{$APPTYPE CONSOLE}
uses
Types;
{$IFDEF FPC}
function DynArraySize(p : pointer): tdynarrayindex; external name
'FPC_DYNARRAY_LENGTH';
{$ENDIF}
procedure Foo(A: Pointer);
begin
WriteLn(DynArraySize(A));
end;
type
TFoo = procedure(const A: TIntegerDynArray);
var
Test: TFoo;
begin
Test := @Foo;
Test(TIntegerDynArray.Create(1, 2, 3, 4));
ReadLn;
end.
------ code ------
In Delphi all is ok (DynArraySize in Foo returns 4). In FPC DynArraySize
return 1 (and program crash at the end). Is dynamic array with const
modifier in FPC passed by value? With small modifications especially for
FPC (by adding constref) all works fine:
------ code ------
procedure Foo(constref A: Pointer);
begin
WriteLn(DynArraySize(A));
end;
type
TFoo = procedure(constref A: TIntegerDynArray);
------ code ------
I can live with constref, but I'm much worried by this behavior (in version
without constref). Why my code don't work in both compilers same? I would
like to understand...
Regards,
HNB
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel