<div dir="ltr">2016-02-17 14:58 GMT-02:00 Jonas Maebe <span dir="ltr"><<a href="mailto:jonas.maebe@elis.ugent.be" target="_blank">jonas.maebe@elis.ugent.be</a>></span>:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Mazola Winstrol wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
1 - Does the compiler automatically initialize all class fields when a<br>
new instance is created?<br>
</blockquote>
<br></span>
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.<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2 - Does the compiler initialize record fields?<br>
</blockquote>
<br></span>
Only for fields that are managed types.<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
3 - When i declare a pointer as a global variable or as a member of a<br>
record, can i assume that its initial value is nil?<br>
</blockquote>
<br></span>
No.<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
4 - Is there any compiler switch regarding initialization of variables?<br>
</blockquote>
<br></span>
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.<br>
<br>
<br>
Jonas<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div><br></div><div class="gmail_extra">Thanks a lot for the explanation!<br><br></div><div class="gmail_extra">Regards<br></div><div class="gmail_extra"><br></div></div>