[fpc-pascal] var parameter
cobines at gmail.com
Fri Apr 30 13:24:30 CEST 2010
2010/4/30 spir ☣ <denis.spir at gmail.com>:
> I wrote a little simulation prog to try and understand better the semantics of var parameters (see below code and output).
> It seems they behave like if passed via pointers, but also locally _operated_ via pointers. Meaning there is in ChangeVar no real local variable n (on the stack). But instead Pascal silently behaves like if using p^ for both getting and setting the variable ('s value) "on-place". This is illustrated by the difference of result between the simulating funcs changePtrVar & changePtrDirect.
> Is this interpretation more or less correct?
> How are var parameters actually implemented?
Yes, var parameters are passed by reference (pointer). See here
More information about the fpc-pascal