Sign in Join

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

Mailing lists / fpc-pascal / 2016-07

Initialization of packed record local variables?

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Bo Berglund

I am getting compile hints "Local variable "<variable name>" does not seem to be initialized" for a number of variables of packed record type.

Does not the FPC compiler reserve and zero the memory area of such variables?

In any case I am using Move() to fill the variables with data from a binary buffer, maybe the compiler is not smart enough to detect this and remove the warning?

(FPC 3.0 and Lazarus 1.6 on Raspberry Pi3)

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 6 lines
I am getting compile hints "Local variable "<variable name>" does not seem to be initialized" for a number of variables of packed record type. Does not the FPC compiler reserve and zero the memory area of such variables?

No.

In any case I am using Move() to fill the variables with data from a binary buffer, maybe the compiler is not smart enough to detect this and remove the warning?

The compiler has no way of knowing if your move statement initializes the full record.

Michael.

Reply by email

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote
> Does not the FPC compiler reserve and zero the memory area of such > variables? No.

Does thios mean that the memory is reserved but not cleared or does it mean that memory is not reserved at all?

Show quoted text 8 lines
> In any case I am using Move() to fill the variables with data from a > binary buffer, maybe the compiler is not smart enough to detect this > and remove the warning? The compiler has no way of knowing if your move statement initializes the full record.

Well, if it has no way of knowing that the record is stuffed with data then why does it issue a notice that it seems uninitialized? Are there other commands it does detect as initialization of the variable?

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 10 lines
On Mon, 18 Jul 2016 21:52:37 +0200 (CEST), Michael Van Canneyt wrote: >> Does not the FPC compiler reserve and zero the memory area of such >> variables? > > No. Does thios mean that the memory is reserved but not cleared or does it mean that memory is not reserved at all?

the memory is reserved, but not initialized.

Show quoted text 13 lines
> >> In any case I am using Move() to fill the variables with data from a >> binary buffer, maybe the compiler is not smart enough to detect this >> and remove the warning? > > The compiler has no way of knowing if your move statement initializes the > full record. > Well, if it has no way of knowing that the record is stuffed with data then why does it issue a notice that it seems uninitialized? Are there other commands it does detect as initialization of the variable?

not that I know of.

you need to assign it a value, you can assign it default(yourtype)

Michael.

Reply by email

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote 7 lines
> Are there other commands it does detect as initialization of the > variable? not that I know of. you need to assign it a value, you can assign it default(yourtype)

OK, I did not know about the default keyword.

Is "default" zero?
i.e.

var
  HD: TSSReadingHeader;
  ..
begin
  HD := Default(TSSReadingHeader);

And now HD.anything is zero?

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 16 lines
On Fri, 22 Jul 2016 11:03:23 +0200 (CEST) Michael Van Canneyt wrote: > On Fri, 22 Jul 2016, leledumbo wrote: > >>> OK, I did not know about the default keyword. >>> >>> Is "default" zero? >> >> http://wiki.lazarus.freepascal.org/FPC_New_Features_3.0#New_compiler_intrinsic_Default > > Or better yet, the official documentation: > > http://www.freepascal.org/docs-html/current/rtl/system/default.html Can the examples be added to official docs?

Good point, will do !

Michael.

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt: Or better yet, the official documentation: http://www.freepascal.org/docs-html/current/rtl…
Michael Van Canneyt wrote

Question please. Using the official documentation as linked to above, how does one find out what versions of the compiler/rtl/fcl support something?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 8 lines
Michael Van Canneyt wrote: > Or better yet, the official documentation: > > http://www.freepascal.org/docs-html/current/rtl/system/default.html Question please. Using the official documentation as linked to above, how does one find out what versions of the compiler/rtl/fcl support something?

One does not - yet.

I am working on leaving the various versions available (notice the 'current' in the URL) and then you could view previous versions...

Michael.

Reply by email

Bo Berglund
to Bo Berglund: On Mon, 18 Jul 2016 23:30:47 +0200 (CEST), Michael Van Canneyt OK, I did not know about…
Bo Berglund wrote 13 lines
>you need to assign it a value, you can assign it default(yourtype) > Is "default" zero? i.e. var HD: TSSReadingHeader; .. begin HD := Default(TSSReadingHeader); And now HD.anything is zero?

I made a test once I got the other issues solved and indeed Default() on my packed records seems to zero out the memory! Very good to know! :)

Thanks for pointing it out!

Bo Berglund Developer in Sweden

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt: One does not - yet. I am working on leaving the various versions available (notice the…
Michael Van Canneyt wrote 17 lines
On Fri, 22 Jul 2016, Mark Morgan Lloyd wrote: > Michael Van Canneyt wrote: > >> Or better yet, the official documentation: >> >> http://www.freepascal.org/docs-html/current/rtl/system/default.html > > Question please. Using the official documentation as linked to above, > how does one find out what versions of the compiler/rtl/fcl support > something? One does not - yet. I am working on leaving the various versions available (notice the 'current' in the URL) and then you could view previous versions...

I started hacking through trying to produce at least a list of functions/procedures and a permuted index from different versions, but I got bogged down in an apparent requirement that the documentation files needed to be processed by the corresponding version of supplied utilities. I'm sure what I did was of little value since I was attacking the problem with insufficient understanding of "the right way to do it" and I'm not even sure where it's got to.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email