Ryan Joseph via fpc-pascal <fpc-pascal@lists.freepascal.org> schrieb am
Mo., 17. Jan. 2022, 02:38:

>
>
> > On Jan 16, 2022, at 11:15 PM, Sven Barth <pascaldra...@googlemail.com>
> wrote:
> >
> > The class type already is a unique "ID" for each class type when doing
> an equal comparison. You can essentially take the address of the VMT as the
> constant values that the loaded value is compared against.
>
> Does that look something like this then? and if so, this is better then
> doing the if-statement block, like string case statements?
>

At least the compiler would be able to optimize it better.


>   case PtrUInt(o.ClassType.ClassInfo) of
>     PtrUInt(TObject.ClassInfo): writeln('TObject');
>   end;
>

No, that is the RTTI. While that would work as well that is an additional
indirection. So it would be more like:

case PtrUInt(o.ClassType) of
    PtrUInt(TObject): writeln('TObject');
  end;


> Question then is how you get the VMT address as a constant at compile time.
>

I'll need to get back to you with that.

Regards,
Sven

>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to