[fpc-pascal] Result: string

José Mejuto joshyfun at gmail.com
Wed Mar 6 23:49:07 CET 2013


El 06/03/2013 13:47, Jonas Maebe escribió:

>> 2.6.0, 2.6.2 and 2.7.1 trunk produces a warning with that code, but
>> with this one 2.6.0, and 2.7.1 trunk does not generate it (I do not
>> have 2.6.2 to test):
>
> That's because you are passing an uninitialized value to a
> var-parameter. That only generates a hint, because a lot of code uses
> var-parameters also for parameters that do not yet have to be
> initialized (because the code predates the existence of the "out"
> keyword, or simply out of habit).
>
> This is unrelated to string results specifically.

Hello,

I had found why I was unable to see the hint, because it is not shown 
due the special contruction of the function.

This code produces a hint for the "Result: String" not initialized, but 
not for the "Result: integer" one:

------------------------------------------
program test;

{$mode objfpc}
{$h+}

procedure TheB(var aTheA: string);

begin
   aTheA:=aTheA+'A';
end;

function TheA(): string;

begin
   TheB(Result);
end;

procedure TheNumberB(var aTheB: integer);

begin
   aTheB:=aTheB*2;
end;

function TheNumberA: integer;

   procedure HideTheHint;

   begin
     //As it is a procedure the "Result" var is taken
     //from the function scope.
     TheNumberB(Result);
   end;

begin
   HideTheHint;
end;

Var
   C : String;
   N : integer;

begin
   C:='B';
   C:=TheA;
   C:=TheA;
   Writeln('= "',C,'"');

   N:=1;
   N:=TheNumberA;
   N:=TheNumberA;
   Writeln('= "',N,'"');
end.
-------------------------------------------

Yes, it is a bit obfuscated. I do not known if this is a bug in the hint.

-- 




More information about the fpc-pascal mailing list