On Tue, 13 Oct 2015, Sven Schreiber wrote:
Am 29.09.2015 um 20:32 schrieb Sven Schreiber:
> Am 29.09.2015 um 18:48 schrieb Allin Cottrell:
>
>> (2) When a matrix is used as an argument to a user-defined function,
>> there are two ways to ensure it is "passed along" to the function
rather
>> than being copied: give the argument in "pointer" form, or
>> mark the argument as "const".
>>
>> So consider a modified version of your script:
>>
>> <hansl>
>> function void hey(const matrix hu)
>> print "hey"
>> end function
>>
>> bundle bbb
>> bbb.in = ones(2,2)
>> hey(bbb.in)
>> </hansl>
>>
>> The matrix bbb.in will not be copied in this case. But if we removed the
>> const flag to the "hu" argument it would get copied on entry to the
>> function.
>>
>
> Ok, very informative. Thanks!
>
A follow-up on this: I just noticed that example 13.1 in the manual has this
function header:
"function scalar b(const matrix *X)"
From what you explained here, the pointer form in this example would be
redundant, right?
Right. That example may have predated the modification whereby "const"
(for pointer-y objects such as matrices) implied pass by reference.
Allin