[fpc-devel] Maybe room for better documentation? open array as var param
Michael Van Canneyt
michael at freepascal.org
Thu Jul 20 23:31:08 CEST 2023
On Thu, 20 Jul 2023, Sven Barth via fpc-devel wrote:
>> It's IMO probably better to outright forbid passing open array by
> 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
>> 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).
I will document the behaviour with the example Martin made.
More information about the fpc-devel