On 20/07/2023 19:24, Michael Van Canneyt via fpc-devel wrote:


It's IMO probably better to outright forbid passing open array by reference.

printing length(a) after x:=Nil; gives 10, which is simply wrong.

The open array is not the same as the dyn array.

It is at any point just a slice of the dyn array. (even if the slice has all elements of the dyn array). At no point is it possible to do a SetLength on the open array (and therefore the lenght of the dyn array can't be changed either - not via the open array).

In otherwise the reference is only a reference to the members.
There is at no point a reference to the dyn array itself, nor to the length.


Of course if the underlaying data goes away, then the "var param" open array  (same as "const param") points to some memory....

I don't know if it needs to be forbidden (don't mind if).
But I think
- explicit documentation
- a compiler note or warning might be helpful


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

Reply via email to