On 03.07.2018 22:08, Florian Klämpfl wrote:
Am 03.07.2018 um 21:30 schrieb Ondrej Pokorny:
On 03.07.2018 20:54, Florian Klämpfl wrote:
program Project1;
type
   TMyArray = array[0..10] of Integer;
   procedure Init2(var A: TMyArray);
   begin
     A[2] := 1;
   end;
var
   A: TMyArray;
begin
   Init2(A);
end.

should not emit the warning because A is not being read in Init2.

(please note it throws only a hint in this case as A *is* initialized as it is a global variable).

You are wrong in both of the 2 assumptions you made in your statement:

*1.) Assumption 1: a warning is thrown when A is not a global variable. Wrong.*

program Project1;
type
   TMyArray = array[0..10] of Integer;
   procedure Init2(var A: TMyArray);
   begin
     A[2] := 1;
   end;
  procedure Test;
  var
    A: TMyArray;
  begin
    Init2(A); // << project1.lpr(12,12) Hint: Local variable "A" does not seem to be initialized
  end;
begin
  Test;
end.

*2.) Assumption 2: A is not initialized if is a not a global variable. Wrong.*

See the very first email in this thread and Sven Barth's reply:

On 24.03.2018 23:00, Sven Barth via fpc-devel wrote:
Ondrej Pokorny <laza...@kluug.net <mailto:laza...@kluug.net>> schrieb am Sa., 24. März 2018, 20:49:

    Another question about this sentence in FPC docs: "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."

    Does it mean I can assume a local string variable is always (=whenever
    the routine is called) initialized to ''? I.e. that TestB always
    returns
    'a'?


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.

Regards,
Sven

Reference in your FPC docs:
https://www.freepascal.org/docs-html/ref/refse24.html

"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."

-----

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...

Yet all my arguments to clear this mess up were refused with the statement that there is no reason to change anything in FPC.

Ondrej
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to