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

Sven Barth pascaldragon at googlemail.com
Sun Jun 26 14:13:42 CEST 2016


Am 26.06.2016 12:10 schrieb "J├╝rgen Hestermann" <juergen.hestermann at gmx.de>:
>
> 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.
> Here
> http://www.freepascal.org/docs-html/ref/refsu15.html
> 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.

But also no word that it is true either, cause you're not declaring a
variable for the Result.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160626/82fac5cd/attachment.html>


More information about the fpc-pascal mailing list