Created attachment 199823 [details] Sample file. When I pass variant array to subroutine by value I can modify the external variable (array) inside the subroutine. Is it by design? If so, the documentation of "ByVal" should state it explicitly. I tested it on Windows 10 x64, Calc 25.2.1.2 and on Linux x64, Calc 6.4.7.2.
@Mike, I thought you might be interested in this issue
Possible misunderstandings with the ByVal construct are related to the fundamentally different behavior of arrays in LO Basic and VBA. Unlike VBA, in LO basic after executing the assignment operator array2=array1 the variables array1 and array2 will refer to the same array instance in memory. Thus, in LO Basic, the behavior of the ByVal construct for array arguments is similar to the behavior for object arguments. After executing the procedure (subroutine, function), the actual parameter - variable will refer to the same array in memory, but this does not guarantee the immutability of the specified array.
> Thus, in LO Basic, the behavior of the ByVal construct for array arguments > is similar to the behavior for object arguments. So perhaps it would be a good idea to remind it in the "ByVal" documentation?
I think it's a good idea. Also, it might be worth explaining the basic concepts. Compare: 1. LO Basic ([1]): ByRef: The argument is passed by reference. ByRef is the default. ByVal: The argument is passed by value. Its value can be modified by the called routine. 2. VBA ([2]): by reference A way of passing the address of an argument to a procedure instead of passing the value. This allows the procedure to access the actual variable. As a result, the variable's actual value can be changed by the procedure to which it is passed. Unless otherwise specified, arguments are passed by reference. by value A way of passing the value of an argument to a procedure instead of passing the address. This allows the procedure to access a copy of the variable. As a result, the variable's actual value can't be changed by the procedure to which it is passed. [1] https://help.libreoffice.org/25.8/en-US/text/sbasic/shared/03090406.html?DbPAR=BASIC [2] https://learn.microsoft.com/en-us/office/vba/language/glossary/vbe-glossary#by-reference
Found a corresponding explanation in LO for ByRef and ByVal ([3]). [3]. https://help.libreoffice.org/25.8/en-US/text/sbasic/shared/01020300.html?&DbPAR=BASIC&System=WIN