On the richness of C++

Bill Baxter dnewsgroup at billbaxter.com
Wed Apr 16 14:48:24 PDT 2008


Sean Kelly wrote:
> == Quote from Sean Kelly (sean at invisibleduck.org)'s article
>> == Quote from Janice Caron (caron800 at googlemail.com)'s article
>>> On 16/04/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
>>>>  The only way to merge function pointers with delegates is to have the
>>>> compiler generate trampolines. This isn't very runtime efficient - the
>>>> template approach will be faster.
>>> I think that all that is being suggested is that function (that which
>>> you get when you take the address of a static or global function)
>>> should implicitly cast to delegate (that which you get when you take
>>> the address of a local or member function).
>> I think the problem is that functions and delegates are called differently.
>> That is, the context pointer is passed as an invisible first parameter to
>> a delegate, while functions have no such invisible argument.  Interestingly,
>> because the first parameter of a D function is supposed to be passed in a
>> register (EAX) on x86, I think you're right that it should be possible to
>> allow such efficient conversion so long as the D calling convention
>> accounts for it properly (and the platform supports such things).
> 
> Er... forget that.  A D function would obviously expect its first argument to
> be in EAX regardless of whether it's a delegate.  Some conversion would be
> necessary unless I'm missing something.

Hmm.  Someone wrote a long post about this long ago and claimed to have 
figured out how to handle it.

--bb



More information about the Digitalmars-d mailing list