Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-08

Incorrect hint message ? ( Hint: Local variable "b" does not seem to be initialized" )

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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.

Vinzent Hoefler
to Skybuck Flying
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.

Skybuck Flying
to Vinzent Hoefler

Fair enough.

Interesting "improvement" over Delphi.

Though it's not much of an improvement ;)

There are other hint messages which are interesting though ;)

Another example:

vByte := vLongint; // warning possible loss of data/range check error.

I like compilers checking up on my code.

Maybe I am gonna give free pascal compiler more tries :)

Though I do wonder what free pascal might have missed that Delphi might have already catched ;)

Since the existing code is already "Delphi prove". So free pascal wasn't used to get the code as far as it's now if you get what I am saying oh well.

Bye,
Skybuck.