The below program compiles fine (and generates no warning (fpc 2.6.2 / win 32)

"c" is an open array. But there is no warning when assigning the [address of c] to a [pointer to dyn array].

Assuming that type safety checks are performed, I would expect a working pointer. But it does not. The pointer point directly to the 1st element of the array. So using it a pointer to a dyn-array, crashes.

So what should happen?
- Should this code work?
- Should this code give a compile error?
- ?



program project1;
type
  TA = array of integer;
  PA = ^TA;
var
  a : array of integer;
  a1: PA;

procedure Foo(var c: array of integer; var c1: PA);
begin
  c1:= @c;

  writeln(PInteger(c1)^);  // writes 100
  writeln(c1^[1]);   //crash
  readln;
end;

begin
  SetLength(a,5);
  a[0]:= 100;
  a[1]:= 101;
  a1:=@a;
  foo(a,a1);
end.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to