Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2005-10

The slice function and bug #2856

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter Popov

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

**************************************************** Peter Popov Postdoctorial Research Assistant, Institute for Scientific Computation Texas A&M University, College Station, TX 77843 Off: (979) 458-4644 Email: ****************************************************

Reply by email

Ales Katona
to Peter Popov
Peter Popov wrote 30 lines
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

Reply by email

Peter Vreman
to Peter Popov: Hi All As you now, the Slice function (internal to the Delphi compiler) is not currently…
Show quoted text 20 lines
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?

Yes

Show quoted text 5 lines
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.

See rtl/inc/dynarr*.inc

Reply by email