[fpc-devel] The slice function and bug #2856
Ales Katona
almindor at gmail.com
Thu Oct 13 11:48:22 CEST 2005
Peter Popov wrote:
> Hi All
> As you now, the Slice function (internal to the Delphi compiler) is
> not currently implented in fpc (see bug
> http://www.freepascal.org/bugs/showrec.php3?ID=2856). I am wondering
> how easy it is to implement/circumvent this problem. In these regard,
> can someone shed light on the following two things:
>
> 1. Are open array parameters in fpc functions and procedure
> implemented in the same way as in Delphi. That is,
>
> procedure MyFunc(x: array of integer)
>
> is actually compiled as
>
> procedure MyFunc(count: Integer; x: ^Integer)
>
> and inside MyFunc, x is treated as a zero based arrays of size count,
> and count is only accessible through High(x).
>
> Are fpc open arrays done in the same way?
>
> 2. What is the internal structure of a dynamic array/open array in
> fpc. Maybe, given a pointer and a array size, one can hack a
> temprorary dynamic array structure (probably without typecasting) and
> pass it as an open array parameter. Even without typecasting, this
> will let me compile existing delphi code.
>
> Thanks
> Peter
>
Array slicing is already possible with the use of absolute eg:
program Project1;
{$mode objfpc}{$H+}
procedure Crap(var A: array of Integer);
var
b: array[1..3] of Integer absolute A[2];
i: Integer;
begin
for i:=1 to 3 do b[i]:=0;
end;
var
a: array of Integer;
i: Integer;
begin
SetLength(a, 6);
for i:=0 to 5 do
a[i]:=i + 1; // 1 to 6
Crap(a);
for i:=0 to 5 do
Write(a[i], ' ');
Writeln;
end.
Output is 1 2 0 0 0 6
Ales
More information about the fpc-devel
mailing list