<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:33, Ondrej Pokorny
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:1ede8d92-41f4-9c85-f66c-dbcc5df71cb9@kluug.net">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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).</blockquote>
<br>
I found the source of my assumption, I get a compiler warning in
this case:<br>
<br>
program StringsTest;<br>
function Test: string;<br>
var S: string;<br>
begin<br>
S := S + 'a';<br>
Result := S;<br>
end;<br>
begin<br>
Writeln(Test);<br>
end.<br>
<br>
Emits:<br>
StringsTest.lpr(5,8) Warning: Local variable "S" of a managed type
does not seem to be initialized<br>
<br>
Why do I get the compiler warning when the variable is indeed
guaranteed to be initialized to nil/empty string?<br>
<br>
Ondrej<br>
</body>
</html>