[fpc-devel] comparing methods

Desmond Coertzen patrolliekaptein at gmail.com
Thu Sep 10 16:25:26 CEST 2009


I have done some horrible code where I needed to know the following:

If TSomeProc = procedure(....), then is it easy to determine or set entry
vector of ThatProc: TSomeProc by stating ThatProc :=
@ProcWhereTheCodeLives_InTheCodeSegment;

It gets more difficult when you work with TSomeClassProc = procedure(....)
of object, because two parts are referenced here: 1) The entry vector where
the code lives, 2) The heap address where the object struct lives. (Known as
the Self variable in a procedure of object)

I have worked out which pointer of the two pointers belongs to the code and
which to the instance with a trial. With a move operation, I was able to
manipulate the two pointers, specifically to determine the address of the
instance.

The @ operator only gives you access to the procedure part. Is there, or
will there be, another operator to give you access to the instance address?

2009/9/10 Mattias Gärtner <nc-gaertnma at netcologne.de>

> Zitat von Vincent Snijders <vsnijders at vodafonevast.nl>:
>
>  Jonas Maebe schreef:
>>
>>>
>>> On 10 Sep 2009, at 14:01, Mattias Gärtner wrote:
>>>
>>>
>>>>> Mattias Gärtner wrote:
>>>>>
>>>>>> Can someone explain why in mode objfpc comparing methods only compares
>>>>>> the address, but not the instance?
>>>>>>
>>>>>
>>>>> Seems perfectly logical to me (@ = Address of, in this case "code
>>>>> address", the code is the same for all instances of a class).
>>>>>
>>>>
>>>> OnClick:=@MyClick;
>>>>
>>>> The @ operator is more than "address of".
>>>>
>>>
>>> The current behaviour has been there since svn revision 1, so it's quite
>>> old and established at least (and Delphi/TP-compatible, afaik).
>>>
>>
>> It is delphi compatible, not really intuitive, so I would welcome a change
>> in the objfpc mode.
>>
>> See:
>> http://bugs.freepascal.org/view.php?id=9228
>> http://bugs.freepascal.org/view.php?id=11868
>>
>
> To draw the whole picture:
>
> var a,b: TNotifyEvent;
>
> a=b         compares only Code, not Data
> a=nil       compares only Data, not Code
> Assigned(a) compares only Code, not Data
> n.a.        compares both
>
> I wonder how many programmers know this.
>
> Even the FCL contains code, where this leads to wrong code.
> More important: I don't know a place, where a=b and a=nil are used right.
> But I have seen a lot of code where it was used wrong.
>
>
> Mattias
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20090910/e5982a1a/attachment.html>


More information about the fpc-devel mailing list