[fpc-pascal] Undocumented SetLength functionality
    Torsten Bonde Christiansen 
    tc at epidata.info
       
    Mon May 14 15:23:04 CEST 2018
    
    
  
Hi All.
I just discovered that SetLength(Var S: Array; NewLength: Integer) has 
an undocumented (appenrently unlimited number of) overloaded functions.
Any multi dimentional arrays may be sent to SetLength with appropriate 
dimension sizes. Making the following possible:
program SetArrayLength;
var
   Int2Array: Array of Array of Integer;
   Int3Array: Array of Array of Array of Integer;
// ...etc
begin
   SetLength(Int2Array, 5, 5);
   SetLength(Int3Array, 5, 5, 5);
// ... etc
   Int2Array[2][2]    := 2;
   Int3Array[2][2][2] := 3;
   WriteLn(IntArray[2][2]);
   WriteLn(IntArray[2][2][2]);
end;
Is this a feature, bug or undocumented behaviour?
Afair, this was allowed back in Delphi7 (which is where i copied some of 
my old code from), but i'm not sure whether it was documented.
At least the current RTL documentation on SetLength does not include 
other variants than the one with just a single length specifier.
https://www.freepascal.org/docs-html/rtl/system/setlength.html
Best regards,
Torsten.
    
    
More information about the fpc-pascal
mailing list