[fpc-devel] Wrong docs: not initialized global variables

Ondrej Pokorny lazarus at kluug.net
Sat Jul 7 08:18:45 CEST 2018


On 07.07.2018 08:05, Ondrej Pokorny wrote:
> 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).
>
> *2.) Assumption 2: A is not initialized if is a not a global variable. 
> Wrong.*


I forgot to say: this is valid for managed types only. But all my 
arguments are valid anyway. See local variables:

program Project1;
   procedure InitS(var S: string);
   begin
   end;
   procedure InitI(var I: Integer);
   begin
   end;
   procedure Test;
   var
     S: string;
     I: Integer;
   begin
     InitS(S); // << project1.lpr(13,12) Hint: Local variable "S" of a 
managed type does not seem to be initialized
     InitI(I); // << project1.lpr(14,12) Hint: Local variable "I" does 
not seem to be initialized
   end;
begin
   Test;
end.

program Project1;
   procedure InitS(var S: string);
   begin
   end;
   procedure InitI(var I: Integer);
   begin
   end;
var
   S: string;
   I: Integer;
begin
   InitS(S); // << project1.lpr(13,10) Hint: Variable "S" of a managed 
type does not seem to be initialized
   InitI(I); // << project1.lpr(14,10) Hint: Variable "I" does not seem 
to be initialized
end.

As you see, all messages are hints only, no warnings. Regardless of 
managed/not-managed global/local variable.

Ondrej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180707/fe0141cd/attachment.html>


More information about the fpc-devel mailing list