[fpc-pascal] Re: Correct use of var in function calls?
Michael Van Canneyt
michael at freepascal.org
Sat Feb 5 13:27:34 CET 2011
On Sat, 5 Feb 2011, Bo Berglund wrote:
> On Sat, 5 Feb 2011 09:24:44 +0100 (CET),
> michael.vancanneyt at wisa.be wrote:
>
>>
>> No. Someone misunderstands the concept of dynamic array here.
>>
>> A "dynamic array" is a pointer to an array in memory.
>> So when passing a dynamic array to a function,
>> you are, in fact, passing a pointer.
>>
>>> So is there a difference here between Delphi7 and FPC?
>>
>> No.
>>
>
> So in effect it means that all of these calls are exactly the same:
>
> FillArr(const Arr: TByteArr)
> FillArr(var Arr: TByteArr)
> FillArr(Arr: TByteArr)
>
> At least as long as the FillArr function does not attempt to change
> the ponter itself like this:
>
> Arr := SomeOtherArr;
Indeed.
>
> In which case I guess that the only version that will carry this back
> to the caller is the var version?
Yes.
>
> But that is not what I am doing at all, so I can stick with a simple:
>
> FillArr(Arr: TByteArr)
>
> and be sure that I will not get back a different array, but instead
> get my array filled as requested...
It should, yes.
Michael.
More information about the fpc-pascal
mailing list