<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 24.03.2018 23:00, Sven Barth via
fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFMUeB-y4B6mQtJ5bBhdoyU90kK1Bn1EnVZMSObN+f1k175aDg@mail.gmail.com">
<div dir="auto">
<div>
<div class="gmail_quote">
<div dir="ltr">Ondrej Pokorny <<a
href="mailto:lazarus@kluug.net" moz-do-not-send="true">lazarus@kluug.net</a>>
schrieb am Sa., 24. März 2018, 20:49:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">This is
not correct. Global simple variables are always
initialized. At<br>
least in Delphi it is so:<br>
<a
href="http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Variables_%28Delphi%29"
rel="noreferrer noreferrer" target="_blank"
moz-do-not-send="true">http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Variables_(Delphi)</a>
"If<br>
you do not explicitly initialize a global variable, the
compiler<br>
initializes it to 0."<br>
</blockquote>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">So, Delphi *does* document it. Okay, in that
case the documentation needs to be updated, cause up to now
the assumption has been that this is an implementation detail.</div>
</div>
</blockquote>
<br>
It has always been so in Delphi - at least since I learnt it. The
Delphi 7 docs (I can't find older docs online) state it as well:
<a class="moz-txt-link-freetext" href="http://docs.embarcadero.com/products/rad_studio/cbuilder6/EN/CB6_ObjPascalLangGuide_EN.pdf">http://docs.embarcadero.com/products/rad_studio/cbuilder6/EN/CB6_ObjPascalLangGuide_EN.pdf</a>
on page 5-38 "If you don’t explicitly initialize a global variable,
the compiler initializes it to 0." (Docs are at
<a class="moz-txt-link-freetext" href="http://docs.embarcadero.com/products/rad_studio/">http://docs.embarcadero.com/products/rad_studio/</a> )<br>
<br>
<blockquote type="cite"
cite="mid:CAFMUeB-y4B6mQtJ5bBhdoyU90kK1Bn1EnVZMSObN+f1k175aDg@mail.gmail.com">
<div dir="auto">
<div dir="auto">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Another question about this sentence in FPC docs: "Managed
types are<br>
always initialized: in general this means setting the
reference count to<br>
zero, or setting the pointer value of the type to Nil."<br>
<br>
Does it mean I can assume a local string variable is
always (=whenever<br>
the routine is called) initialized to ''? I.e. that TestB
always returns<br>
'a'?<br>
</blockquote>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">For managed types this is indeed guaranteed.
Otherwise there'd be exceptions upon the first use of the
variable as the RTL would assume that the value is valid.</div>
</div>
</blockquote>
<br>
OK, thanks. My assumption was that setting local managed types to
nil is guaranteed only once at the first routine call. And that it
is an implementation detail if it is niled at the second call or
reused from the first call.<br>
<br>
I probably mixed it up with the Result variable (what Maciej wrote
about).<br>
<br>
Ondrej<br>
</body>
</html>