On Thu, 20 Jul 2023, Sven Barth via fpc-devel wrote:
It's IMO probably better to outright forbid passing open array by
reference.
There are valid use cases for that. E.g. multiply a slice of a dynamic
array by two or whatever. And forbidding var would solve nothing, see
below.
printing length(a) after x:=Nil; gives 10, which is simply wrong.
That is true for many cases where you modify the global variable that has
been passed on by reference, e.g. with constant parameters: the compiler
will more often than not pass a reference then, because it's more optional
and the function can't modify it anyway, but if you change the global that
was passed in you get what you deserve... (that's true no matter if it's an
open array, a string or a primitive type).
Valid point...
I will document the behaviour with the example Martin made.
Michael.
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel