Sign in Join

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

Mailing lists / fpc-pascal / 2013-11

Over-zealous Warning about dynamic string initialization

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Howard Page-Clark

The following program:

program Project1;
{$mode objfpc}{$H+}
var
   s:ansistring;
begin
   WriteLn('s <',s,'> always seems to be initialized to ''''');
end.

produces a Warning

Warning: Variable "s" does not seem to be initialized

Can this Warning be disabled for compiler-managed variables?

Howard

Michael Van Canneyt
to Howard Page-Clark
Howard Page-Clark wrote 18 lines
The following program: program Project1; {$mode objfpc}{$H+} var s:ansistring; begin WriteLn('s <',s,'> always seems to be initialized to '''''); end. produces a Warning Warning: Variable "s" does not seem to be initialized Can this Warning be disabled for compiler-managed variables?

I recommend against it.

It can bite you in the leg, it has bitten me in the leg several times. For instance the result identifier for functions returning ansistring is particularly tricky.

Michael.

Jonas Maebe
to Howard Page-Clark: The following program: program Project1; {$mode objfpc}{$H+} var s:ansistring; begin…
Howard Page-Clark wrote 12 lines
var s:ansistring; begin WriteLn('s <',s,'> always seems to be initialized to '''''); end. produces a Warning Warning: Variable "s" does not seem to be initialized Can this Warning be disabled for compiler-managed variables?

The point of the warning is that you did not assign a value to the variable, not necessarily that the contents are unknown. You get the same warning for global variables if you only use them in a main program. Removing unnecessarily assigning an empty string to such values would be a job for the compiler (which it currently does not yet do).

Jonas

Dmitry Boyarintsev
to Michael Van Canneyt: I recommend against it. It can bite you in the leg, it has bitten me in the leg several…
Michael Van Canneyt wrote 5 lines
I recommend against it. It can bite you in the leg, it has bitten me in the leg several times. For instance the result identifier for functions returning ansistring is particularly tricky.

I'm wondering if it's a question about global vs local variables warning: http://lists.freepascal.org/lists/fpc-devel/2012-November/030337.html

The warning is true for local vars and indeed it bites! (bites good when porting delphi to fpc), but should not be a problem for global vars (as in example above).

thanks,
Dmitry