Say I have an associative array of pointers to structs to strings, where the struct is called Foo
; the type will be Foo*[string]
. Suppose I also have a function with the following signature: void bar (Foo*[string] baz)
. Will baz
be passed to bar
by value or by reference? I've not found any documentation about this, and I'm curious.
By reference - any modifications to an existing AA will be observed outside of the function.
However, there is a corner case for when the associative array is null
. In that case, initializing the AA by adding the first element will not be observed outside of the function. If the AA to be modified might be null
, you should pass it by-ref
.
It's like in Java. It's pass-by-value, but the value is a reference.
So you can't change the reference itself, but you can modify the AA it refers to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With