[fpc-devel] Initialize/Finalize management operators and Default intrinsic
Maciej Izak
hnb.code at gmail.com
Mon Apr 11 08:37:29 CEST 2016
2016-04-10 23:54 GMT+02:00 Sven Barth <pascaldragon at googlemail.com>:
> There are two things to differentiate:
>
> - Default() used in global variables
> - Default() used locally
>
> The latter creates a local variable and basically FillChar()s it while the
> former creates a zero initialized global variable.
> (Thinking about this I could use the global variable approach also for
> local uses of Default(), with the only special case being generics, but
> that's another topic...)
>
> So in the local case you'd need to add an Initialize() after the
> FillChar() call (if I haven't done that already).
> In the global case you'd need to add the corresponding calls to the
> implicit initialization function which is called before the unit's
> initialization section. Currently class constructors are called before
> that, but that's not good (though the implications are worse with the
> finalization) and is subject to change. Please don't work around it
> although right now it would work incorrectly for such variables used in
> class constructors.
>
> Thanks for introduction. Workaround is not a case, eventually patch to fix
order of class constructor/destructor and variable implicit
initialization/finalization (as mentioned in
http://bugs.freepascal.org/view.php?id=29245 ). Anyway I do research in
this direction to cover all possible usage of new operators (seems like
Default intrinsic is the last one).
Sven, could you look at topic "Management operators AddRef and Copy vs
Copy" thread? New operators are ready for test in branch, anyway we can
adjust the naming of AddRef and Copy. Florian proposed "Clone" (instead of
Copy) and "Copy" (instead of AddRef).
> Note: and don't forget the finalization ;)
>
"Finalize" is mentioned in thread name so it will not be forgotten ;)
--
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160411/1cf9c9d9/attachment.html>
More information about the fpc-devel
mailing list