[fpc-pascal] Incorrect hint message ? ( Hint: Local variable b does not seem to be initialized )

2007-08-22 Thread Skybuck Flying

Hello,

The following hint message is displayed, which I doubt is correct which 
makes it interesting:


project1.lpr(21,5) Hint: Local variable b does not seem to be 
initialized


Unfortunately the debugger is not working on my system, Lazarus does not 
have a disassembly view so I can't see what's going on at assembly level.


However when looking at the source code this hint message seems inaccurate.

B is initialized by the procedure test.

Demonstration/test program:

// *** Begin of Code ***

program project1;

{$mode objfpc}{$H+}

uses
 {$IFDEF UNIX}{$IFDEF UseCThreads}
 cthreads,
 {$ENDIF}{$ENDIF}
 Classes
 { add your units here };

procedure test( var b : byte );
begin
   b := 5;
end;

procedure useit;
var
   b : byte;
begin
   test( b );

   writeln( b );
end;

begin
   writeln('program started');

   useit;

   writeln('press enter to exit');
   readln;

   writeln('program finished');
end.

// *** End of Code ***

I sent this message to free pascal and lazarus mailing lists because I am 
not sure which program is generating the hint message ?


(Free Pascal Compiler or Lazarus ?)

Me thinks FPC but I am not 100% sure ;)

Bye,
 Skybuck. 


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Incorrect hint message ? ( Hint: Local variable b does not seem to be initialized )

2007-08-22 Thread Vinzent Hoefler
On Wednesday 22 August 2007 06:30, Skybuck Flying wrote:

 project1.lpr(21,5) Hint: Local variable b does not seem to be
 initialized

[...]

 However when looking at the source code this hint message seems
 inaccurate.

 B is initialized by the procedure test.

No, it's not. It says var, so according to the contract the procedure 
test is supposed to get an already initialized value (and may change 
it when executing).

[...]

 procedure test( var b : byte );
 begin
 b := 5;
 end;

[...]

If you want test to really initialize the variable and not care about 
its incoming value, you should use parameter mode out instead.


Vinzent.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal