[fpc-pascal] More fun with dynamic arrays

andrew.bennett at ns.sympatico.ca andrew.bennett at ns.sympatico.ca
Fri Nov 18 01:40:39 CET 2011


This program:

Program TestMem ;
Const ASize = 1000 ;
Type DataA = Array Of Longint ;
Var A : DataA ;
Procedure Init(Out X : DataA ; Const N : Longint) ;
Begin
  Writeln(Length(X)) ; { Writes: 0 }
End ;
Begin
  SetLength(A, ASize) ;
  Writeln(Length(A)) ; { Writes: 1000 as expected }
  Init(A, ASize) ;
End.

gives the results noted in the comments.
The correct results are obtained if
1) I substitute "Var" for "Out". This leads to the warning that X is not
initialized.
2) I substitute "Array Of Longint" for "DataA".
What am I doing wrong this time?

Andrew Bennett

 



More information about the fpc-pascal mailing list