[fpc-pascal] initializing pointer values

noreply at z505.com noreply at z505.com
Sat Dec 17 07:21:18 CET 2011


>
>
> On Fri, 16 Dec 2011, dhkblaszyk at zeelandnet.nl wrote:
>
>>
>> On implementing a linked list I hit to some unexpected (doesn't mean
>> incorrect though) behaviour.
>>
>>  
>>
>>   ptest = ^test;
>>   test = record
>>      p: pointer;
>>   end;
>>
>>  
>>
>>   new(mytest);
>>
>>  
>>
>> When I allocate "mytest" the pointer variable "p" is initialized as
>> $ffffffff instead of nil as I did suspect. In my code though I am
>> relying on the fact that new pointers are indeed nil so I can allocate
>> them accordingly. How can I force and rely on the fact that
>> p is always nil? What is the correct procedure here?
>
> Newly allocated memory is never zeroed out. You must do this manually with
> FillChar or FillWord.
> This is only done automatically for class instances.
>
> I will add a note to the docs.
>
> Michael.

Also you can Zero out records using:

var r: TSomeRec = ();

Or access the record fields and nil out the ones you want, but () gets it
all done in one shot.



More information about the fpc-pascal mailing list