Sign in Join

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

Mailing lists / fpc-pascal / 2013-12

Warning: Variable xxx does not seem to be initialized

11 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Marcos Douglas

Hi,

I'm using FPC 2.6.2 and {advancedrecords}.
The compiler shows a warning when I use a record variable. IMO this is a bug because record variables need not be initialized, right?

project1.lpr(20,3) Warning: Variable "r" does not seem to be initialized
=== BEGIN ===
program Project1;
{$mode objfpc}{$H+}
{$modeswitch advancedrecords}
type
  TMyRec = record
    procedure Print;
  end;
procedure TMyRec.Print;
begin
  writeln('foo');
end;
var
  r: TMyRec;
begin
  r.Print;
end.
=== END ===

Marcos Douglas

Reply by email

Sven Barth
to Marcos Douglas
"Marcos Douglas" wrote 6 lines
Hi, I'm using FPC 2.6.2 and {advancedrecords}. The compiler shows a warning when I use a record variable. IMO this is a bug because record variables need not be initialized, right?

Managed types (strings, interfaces, dynamic arrays) inside a record will have a valid value (Nil), but other values will he garbage. The compiler does not check whether a record contains any non-managed fields before generating the warning.

Regards,
Sven

Reply by email

Sven Barth
to Dmitry Boyarintsev

Am 31.12.2013 00:48 schrieb "Dmitry Boyarintsev" <

Show quoted text 13 lines
: Some new syntax has to be introduced to avoid the warning. Something like: type TMyRec = record record procedure Print; end; record procedure TMyRec.Print; begin writeln('foo'); end;

We don't need a new syntax for something that already works:

=== code begin ===

type
 TMyRec = record
    class procedure Print; static;
  end;
class procedure TMyRec.Print;
begin
 writeln('foo');
end;
begin
  TMyRec.Print;
end.

=== code end ===

Regards,
Sven

Reply by email

Marcos Douglas
to Sven Barth: Managed types (strings, interfaces, dynamic arrays) inside a record will have a valid…
Sven Barth wrote 14 lines
Am 30.12.2013 20:08 schrieb "Marcos Douglas" : > > Hi, > > I'm using FPC 2.6.2 and {advancedrecords}. > The compiler shows a warning when I use a record variable. IMO this is > a bug because record variables need not be initialized, right? Managed types (strings, interfaces, dynamic arrays) inside a record will have a valid value (Nil), but other values will he garbage. The compiler does not check whether a record contains any non-managed fields before generating the warning.

Ok. But is this will be "corrected" in the next version? Because if won't, I can not see sense to use it.
The structure that does same but does not have this problem is the object type. But is it used yet? I think Delphi make it deprecated, right?

Talking about Delphi, it has the same problem with warnings on records?

Thanks,
Marcos Douglas

Reply by email

Marcos Douglas
to Sven Barth: Am 31.12.2013 00:48 schrieb "Dmitry Boyarintsev" < We don't need a new syntax for…
Sven Barth wrote 41 lines
Am 31.12.2013 00:48 schrieb "Dmitry Boyarintsev" : > > Some new syntax has to be introduced to avoid the warning. Something like: > > type > TMyRec = record > record procedure Print; > end; > > record procedure TMyRec.Print; > begin > writeln('foo'); > end; We don't need a new syntax for something that already works: === code begin === type TMyRec = record class procedure Print; static; end; class procedure TMyRec.Print; begin writeln('foo'); end; begin TMyRec.Print; end. === code end === Regards, Sven

Yes, but if is need to use like this, is better using the sintaxe Unit.Function...
I would like to use a variable (short name) but without initialize it (Constructor).

Regards,
Marcos Douglas

Reply by email

Sven Barth
to Marcos Douglas: Ok. But is this will be "corrected" in the next version? Because if won't, I can not see…
Marcos Douglas wrote 18 lines
On Mon, Dec 30, 2013 at 9:38 PM, Sven Barth wrote: > Am 30.12.2013 20:08 schrieb "Marcos Douglas" : > > >> >> Hi, >> >> I'm using FPC 2.6.2 and {advancedrecords}. >> The compiler shows a warning when I use a record variable. IMO this is >> a bug because record variables need not be initialized, right? > > Managed types (strings, interfaces, dynamic arrays) inside a record will > have a valid value (Nil), but other values will he garbage. The compiler > does not check whether a record contains any non-managed fields before > generating the warning. Ok. But is this will be "corrected" in the next version? Because if won't, I can not see sense to use it.

It seems that this was already corrected at least in trunk as a test with 2.7.1 does not show a warning anymore. I don't know whether the corresponding fix was merged to 2.6.3 though (I assume "no" by default for compiler changes though).

The structure that does same but does not have this problem is the object type. But is it used yet? I think Delphi make it deprecated, right?

What do you mean "But is it used yet?"? And yes, Borland, Codegear, Embarcadero, whoever decided that "object" is deprecated in Delphi in FPC however they are still fully working and also benefit from newer features here and then (mostly because "object" shares a lot of code with "class" and "interface").

Talking about Delphi, it has the same problem with warnings on records?

Didn't test that.

Regards,
Sven

Reply by email

Sven Barth
to Marcos Douglas: Yes, but if is need to use like this, is better using the sintaxe Unit.Function... I…
Marcos Douglas wrote 45 lines
On Tue, Dec 31, 2013 at 6:33 AM, Sven Barth wrote: > Am 31.12.2013 00:48 schrieb "Dmitry Boyarintsev" > : > > >> >> Some new syntax has to be introduced to avoid the warning. Something like: >> >> type >> TMyRec = record >> record procedure Print; >> end; >> >> record procedure TMyRec.Print; >> begin >> writeln('foo'); >> end; > > We don't need a new syntax for something that already works: > > === code begin === > > type > TMyRec = record > class procedure Print; static; > end; > > class procedure TMyRec.Print; > > > begin > writeln('foo'); > end; > > begin > TMyRec.Print; > end. > > === code end === > > Regards, > Sven Yes, but if is need to use like this, is better using the sintaxe Unit.Function...

Depends on the preference of the developer I'd say. I personally prefer the usage of "typename.method" instead of "unit.function" for example.

Regards,
Sven

Reply by email

Marcos Douglas
to Sven Barth: It seems that this was already corrected at least in trunk as a test with 2.7.1 does not…
Sven Barth wrote 30 lines
On 31.12.2013 15:06, Marcos Douglas wrote: > > On Mon, Dec 30, 2013 at 9:38 PM, Sven Barth > wrote: >> >> Am 30.12.2013 20:08 schrieb "Marcos Douglas" : >> >> >>> >>> Hi, >>> >>> I'm using FPC 2.6.2 and {advancedrecords}. >>> The compiler shows a warning when I use a record variable. IMO this is >>> a bug because record variables need not be initialized, right? >> >> >> Managed types (strings, interfaces, dynamic arrays) inside a record will >> have a valid value (Nil), but other values will he garbage. The compiler >> does not check whether a record contains any non-managed fields before >> generating the warning. > > > Ok. But is this will be "corrected" in the next version? Because if > won't, I can not see sense to use it. It seems that this was already corrected at least in trunk as a test with 2.7.1 does not show a warning anymore. I don't know whether the corresponding fix was merged to 2.6.3 though (I assume "no" by default for compiler changes though).

If was corrected in 2.7.1 is enough for me.

Show quoted text 6 lines
> The structure that does same but does not have this problem is the > object type. But is it used yet? I think Delphi make it deprecated, > right? What do you mean "But is it used yet?"?

Is recommended to use it or FPC team recommends to use "record" instead?

Show quoted text 5 lines
And yes, Borland, Codegear, Embarcadero, whoever decided that "object" is deprecated in Delphi in FPC however they are still fully working and also benefit from newer features here and then (mostly because "object" shares a lot of code with "class" and "interface").

So, maybe is more useful to use object type instead record type to group functions.

Thanks,
Marcos Douglas

Reply by email

Marcos Douglas
to Sven Barth: Depends on the preference of the developer I'd say. I personally prefer the usage of…
Sven Barth wrote 56 lines
On 31.12.2013 15:09, Marcos Douglas wrote: > > On Tue, Dec 31, 2013 at 6:33 AM, Sven Barth > wrote: >> >> Am 31.12.2013 00:48 schrieb "Dmitry Boyarintsev" >> : >> >> >>> >>> Some new syntax has to be introduced to avoid the warning. Something >>> like: >>> >>> type >>> TMyRec = record >>> record procedure Print; >>> end; >>> >>> record procedure TMyRec.Print; >>> begin >>> writeln('foo'); >>> end; >> >> >> We don't need a new syntax for something that already works: >> >> === code begin === >> >> type >> TMyRec = record >> class procedure Print; static; >> end; >> >> class procedure TMyRec.Print; >> >> >> begin >> writeln('foo'); >> end; >> >> begin >> TMyRec.Print; >> end. >> >> === code end === >> >> Regards, >> Sven > > > Yes, but if is need to use like this, is better using the sintaxe > Unit.Function... Depends on the preference of the developer I'd say. I personally prefer the usage of "typename.method" instead of "unit.function" for example.

Me too, but without warnings. ;-)

I prefer to group procedures/functions (utilities) inside object/record (in classes too, of course) instead using unit.function sintaxe. IMHO the code is more readable and organized.

Regards,
Marcos Douglas

Reply by email

Sven Barth
to Marcos Douglas: If was corrected in 2.7.1 is enough for me. Is recommended to use it or FPC team…
Marcos Douglas wrote 8 lines
>> The structure that does same but does not have this problem is the >> object type. But is it used yet? I think Delphi make it deprecated, >> right? > > > What do you mean "But is it used yet?"? Is recommended to use it or FPC team recommends to use "record" instead?

The methods for records were introduced for Delphi compatibility, so they are rather young compared to objects (which are still used here and then inside the compiler for example, because most code is from a time when records could not have methods). In contrast to objects they however provide support for operator overloads (you need to use these if you want to use overloaded operators inside a generic) and they can have a variant part. Objects however support inheritance if the need arises.

Show quoted text 8 lines
> And yes, Borland, Codegear, > Embarcadero, whoever decided that "object" is deprecated in Delphi in FPC > however they are still fully working and also benefit from newer features > here and then (mostly because "object" shares a lot of code with "class" and > "interface"). So, maybe is more useful to use object type instead record type to group functions.

Depends on the use case and preference. See above.

Regards,
Sven

Reply by email