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

C Western l at c-m-w.me.uk
Sun Jun 26 13:21:40 CEST 2016

On 26/06/16 11:09, J├╝rgen Hestermann wrote:
> 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 := '';

My understanding (having been bitten by this) is that the requirement is 
only that S has a "sensible" value, so that the heap is not corrupted on 
the assignment, as you indicate. The compiler can re-use another 
variable instead, so the unset value is some other valid string.


More information about the fpc-pascal mailing list