Sign in Join

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

Mailing lists / fpc-pascal / 2018-05

Undocumented SetLength functionality

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Torsten Bonde Christiansen

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.

Reply by email

Sven Barth
to Torsten Bonde Christiansen

Torsten Bonde Christiansen schrieb am Di., 15. Mai 2018, 12:03:

Is this a feature, bug or undocumented behaviour?

This is a feature and absolutely by design.

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

While it's not explicitly mentioned it's at least used in one f the examples for dynamic arrays in the language guide: https://freepascal.org/docs-html/current/ref/refse14.html#QQ2-38-57 Maybe this can indeed be clarified a bit.

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 21 lines
Torsten Bonde Christiansen schrieb am Di., 15. Mai 2018, 12:03: > Is this a feature, bug or undocumented behaviour? > This is a feature and absolutely by design. > 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 While it's not explicitly mentioned it's at least used in one f the examples for dynamic arrays in the language guide: https://freepascal.org/docs-html/current/ref/refse14.html#QQ2-38-57 Maybe this can indeed be clarified a bit.

Indeed. Please enter a bugreport so I do not forget it.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt

Michael Van Canneyt schrieb am Di., 15. Mai 2018, 14:29:

Show quoted text 29 lines
On Tue, 15 May 2018, Sven Barth via fpc-pascal wrote: > Torsten Bonde Christiansen schrieb am Di., 15. Mai 2018, > 12:03: > >> Is this a feature, bug or undocumented behaviour? >> > > This is a feature and absolutely by design. > > >> 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 > > > While it's not explicitly mentioned it's at least used in one f the > examples for dynamic arrays in the language guide: > https://freepascal.org/docs-html/current/ref/refse14.html#QQ2-38-57 > Maybe this can indeed be clarified a bit. Indeed. Please enter a bugreport so I do not forget it.

Done: https://bugs.freepascal.org/view.php?id=33759

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 34 lines
Michael Van Canneyt schrieb am Di., 15. Mai 2018, 14:29: > > > On Tue, 15 May 2018, Sven Barth via fpc-pascal wrote: > >> Torsten Bonde Christiansen schrieb am Di., 15. Mai > 2018, >> 12:03: >> >>> Is this a feature, bug or undocumented behaviour? >>> >> >> This is a feature and absolutely by design. >> >> >>> 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 >> >> >> While it's not explicitly mentioned it's at least used in one f the >> examples for dynamic arrays in the language guide: >> https://freepascal.org/docs-html/current/ref/refse14.html#QQ2-38-57 >> Maybe this can indeed be clarified a bit. > > Indeed. Please enter a bugreport so I do not forget it. > Done: https://bugs.freepascal.org/view.php?id=33759

Thank you. With examples and all, I couldn't wish for more... :)

Michael.

Reply by email