Recent

Author Topic: Advanced Records Initialisation bug ?  (Read 1918 times)

Nitorami

  • Sr. Member
  • ****
  • Posts: 431
Re: Advanced Records Initialisation bug ?
« Reply #15 on: October 24, 2022, 09:22:40 pm »
Coming back to this presumed bug - I have not filed a bug report yet because I am uncertain. Up to now I thought that an advanced record would be initialized at runtime on the first access to any of its methods, simply by checking a flag. This would introduce a bit of overhead and speed penalty as the flag would have to be checked on each and every method call, but this may just be the price for the convenience.

But then I found, rather surprisingly, that aGen is initialized properly whenever a local function somewhere within testunit.pas merely mentions one of aGen's methods. The function may never be called, its existence alone is sufficient to prompt the compiler to initialize aGen. Something like this in the unit's implementation part does the job:

Code: Pascal  [Select][+][-]
  1. procedure neverused;
  2. begin
  3.   if false then writeln (aGen.content);
  4. end;

It looks like the compiler does a static analysis at compile time to guess if aGen will be called from somwehere, and if yes, initializes it at program start within fpc_initizalizeunits() ?

 

TinyPortal © 2005-2018