<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 03.07.2018 22:08, Florian Klämpfl
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:7b8583ba-fa60-7579-6dc3-e25e95185afc@freepascal.org">Am
03.07.2018 um 21:30 schrieb Ondrej Pokorny:
<br>
<blockquote type="cite">On 03.07.2018 20:54, Florian Klämpfl
wrote:
<br>
</blockquote>
<blockquote type="cite">
program Project1;
<br>
type
<br>
TMyArray = array[0..10] of Integer;
<br>
procedure Init2(var A: TMyArray);
<br>
begin
<br>
A[2] := 1;
<br>
end;
<br>
var
<br>
A: TMyArray;
<br>
begin
<br>
Init2(A);
<br>
end.
<br>
<br>
should not emit the warning because A is not being read in
Init2.
<br>
</blockquote>
<br>
(please note it throws only a hint in this case as A *is*
initialized as it is a global variable).</blockquote>
<br>
You are wrong in both of the 2 assumptions you made in your
statement:<br>
<br>
<b>1.) Assumption 1: a warning is thrown when A is not a global
variable. Wrong.</b><br>
<br>
program Project1;<br>
type<br>
TMyArray = array[0..10] of Integer;<br>
procedure Init2(var A: TMyArray);<br>
begin<br>
A[2] := 1;<br>
end;<br>
procedure Test;<br>
var<br>
A: TMyArray;<br>
begin<br>
Init2(A); // << project1.lpr(12,12) Hint: Local variable
"A" does not seem to be initialized<br>
end;<br>
begin<br>
Test;<br>
end.<br>
<br>
<b>2.) Assumption 2: A is not initialized if is a not a global
variable. Wrong.</b><br>
<br>
See the very first email in this thread and Sven Barth's reply:<br>
<br>
<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">lazarus@kluug.net</a>>
schrieb am Sa., 24. März 2018, 20:49:<br>
</div>
</div>
</div>
<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 dir="auto"><br>
</div>
<div dir="auto">Regards, </div>
<div dir="auto">Sven</div>
</div>
</blockquote>
<br>
Reference in your FPC docs:<br>
<a class="moz-txt-link-freetext" href="https://www.freepascal.org/docs-html/ref/refse24.html">https://www.freepascal.org/docs-html/ref/refse24.html</a><br>
<br>
"Managed types are always initialized: in general this means setting
the reference count to zero, or setting the pointer value of the
type to Nil."<br>
<br>
-----<br>
<br>
The fact that even you as the very first FPC developer are confused
by the warning/hint and initialization/noinitialization
documentation mess makes me feel I have been always right in this
thread...<br>
<br>
Yet all my arguments to clear this mess up were refused with the
statement that there is no reason to change anything in FPC.<br>
<br>
Ondrej<br>
</body>
</html>