[fpc-pascal] Variable Initialization Questions

Mazola Winstrol mazofeifer at gmail.com
Thu Feb 18 19:39:38 CET 2016


2016-02-17 15:16 GMT-02:00 Jonas Maebe <jonas.maebe at elis.ugent.be>:

> Jonas Maebe wrote:
>
>> 3 - When i declare a pointer as a global variable or as a member of a
>>> record, can i assume that its initial value is nil?
>>>
>>
>> No.
>>
>
> Correction: all global variables are always zeroed, so that includes
> pointers, records and hence also pointers in records (if those records
> themselves are global variables). Pointers, records or record fields in are
> not zeroed because they are pointers/records/record fields though (so not
> in case they are local variables).


Just to clarify: if i have a record type with a pointer field, this field
will always zeroed?

e.g

type
   TMyRecord = record
   private
     FMyPointer: Pointer;
   public
     property MyPointer: Pointer read FMyPointer;
   end;

......

procedure ShowMyPointerValue;
var
  MyRecord: TMyRecord;
begin
  writeln('My pointer value: ' + IntToStr(Integer(MyRecord.MyPointer)));
end;

end.


is correct to say that the above code will always print 'My pointer value:
0'?

Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160218/8998f4f2/attachment.html>


More information about the fpc-pascal mailing list