[fpc-pascal] which "managed" result types require extra work?

J├╝rgen Hestermann juergen.hestermann at gmx.de
Tue Jun 28 18:00:18 CEST 2016

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.

It is so logical that managed types are managed (therefore the wording!).
That a function result can inherit old values from prior calls is just the same as for
local constants of TP.  But in TP it was at least documented and it was predictable.
Now everybody ostracizes such behaviour but instead intruduces the same
for function results.

I used this behaviour of managed types over many years.
Now we all (most of us) had to find out the change the hard way (by debugging).
Many may not even have found this yet because their functions with managed type results are used seldomly.
That's quite ignorant C style (where you also have nothing to rely on but need to check every compiler (version)).
So yes, "modern" Pascal is no longer the "old" Pascal, but has it become better? Meanwhile I doubt this.

And what about perfomance? In most of the cases I am now initializing
what is already initialized. Very strange.

More information about the fpc-pascal mailing list