[fpc-pascal] Variable Initialization Questions
Jonas Maebe
jonas.maebe at elis.ugent.be
Wed Feb 17 17:58:01 CET 2016
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
More information about the fpc-pascal
mailing list