[fpc-pascal] why can't we define class operator for old fashion object type, but ok for 'advanced record' type?
Sven Barth
pascaldragon at googlemail.com
Sat Aug 18 03:19:55 CEST 2018
Ryan Joseph <ryan at thealchemistguild.com> schrieb am Fr., 17. Aug. 2018,
18:22:
>
>
> > On Aug 16, 2018, at 8:55 AM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > It shouldn't be hard. Feel free to provide a patch together with some
> tests and it will be taken under consideration.
>
> So the reason that objects/classes in FPC don’t have operators in the
> class (like advanced records) is for Delphi compatibility? That would be
> great if operators were unified across records/classes.
>
Not entirely. In Delphi objects are deprecated, so as long as old code
keeps compiling and running we can mess with them.
However for classes there is the problem of temporary variables. Take a :=
b + c + d. That is essentially compiled as t := b + c; a := t + d. The
compiler does not know whether the operator creates an instance or not
(yes, there are circumstances when it can know that, but for the general
case it can't) and thus this would potentially lead to memory leaks.
Thus automatic reference counting or garbage collection or something like
that is required for this to work nicely.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180818/08907cfc/attachment.html>
More information about the fpc-pascal
mailing list