[fpc-pascal] which "managed" result types require extra work?
Michael Van Canneyt
michael at freepascal.org
Tue Jun 28 20:05:54 CEST 2016
On Tue, 28 Jun 2016, Jürgen Hestermann wrote:
> Am 2016-06-28 um 01:13 schrieb David Emerson:
>> The source of my confusion -- and I suspect that of many others -- is that
> I always assumed a function result was treated like a local variable within
> the function, rather than a parameter to the function.
>> Since managed types are automatically initialized when they are local
> variables, I assumed a function result was the same.
>> Unfortunately, the documentation does not make this sufficiently clear in
> describing managed types. I guess I should file a documentation bug.
>
> Exactly my opinion too.
> Especially, because it behaved differently with Free Pascal versions prior to
> 3!
>
> And it does not behave like a function parameter, it behaves like a *var*
> parameter.
> All other types of parameters behave differently!
> And while a var parameter can *only* be assigned to a variable (so that it is
> clear
> that an existing variable is used) a function result can also be used in an
> expression which makes it silently mutate into a global variable! What a
> mess!
>
> And for local variables I can easily set a default value in the declaration
> but not for the function result.
> I have to remind me not to forget this in the code.
This has been so since day 1 in Pascal.
Any behaviour other than that was entirely coincidental.
Michae.
More information about the fpc-pascal
mailing list