[fpc-pascal] reference-counted function results not initialized to nil

J├╝rgen Hestermann juergen.hestermann at gmx.de
Sun Jun 26 12:09:58 CEST 2016

Am 2016-06-26 um 01:19 schrieb Karoly Balogh (Charlie/SGR):
 > No. Local variables are not initialized by default. Managed type or not,
 > doesn't make a difference.

This is not true.
Local variables of managed types are of course initialized!
If you declare

var S : String;

then it is of course initialized to nil.
Otherwise the (random) pointer stored in S would be used
to change the reference counter when you assign:

S := '';

The only exception (at least since FPC 3) is the function result
which is totally unexpected.
Why such an exception?

And it is not even documented (at least not within FPC)!
Which I find a bit strange because it is very important to know.
Omitting such information in the documentation is not good.
it says:

"When declaring a variable of a dynamic array type, the initial length of the array is zero."

but no word about that this is not true when this array is a the result of a function.

More information about the fpc-pascal mailing list