[fpc-pascal] Variable Initialization Questions

Mazola Winstrol mazofeifer at gmail.com
Wed Feb 17 18:07:57 CET 2016


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

> Mazola Winstrol wrote:
>
>> 1 - Does the compiler automatically initialize all class fields when a
>> new instance is created?
>>
>
> They're called instance fields, and yes, they are zeroed. Class fields are
> fields that that are unique per class type, rather than per instance.
>
> 2 - Does the compiler initialize record fields?
>>
>
> Only for fields that are managed types.
>
> 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.
>
> 4 - Is there any compiler switch regarding initialization of variables?
>>
>
> There is only -gt, but it "initialises" (non-managed) variables and
> out-parameter with random data in order to more easily find cases of
> uninitialised data. It cannot be used to initialise all variables to a
> known value.
>
>
> Jonas
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>

Thanks a lot for the explanation!

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


More information about the fpc-pascal mailing list