Re: delegates with C linkage

2010-06-07 Thread Don
Simen kjaeraas wrote: dennis luehring wrote: D still won't accept an delegat in an extern C because this type does not exists in the C world Nor do classes, and those certainly can be passed to a C-linkage function. Yes, but I think that's a bug too. Quite a horrible one, in fact, since t

Re: delegates with C linkage

2010-06-06 Thread dennis luehring
Am 06.06.2010 17:30, schrieb Zarathustra: are delegats part of the ABI, i can't find a delegat calling scheme in the ABI-Description - should this be in EAX, as last/first part on stack, ECX? The delegates are called by exactly same way as any other member function. Put ptr = 'this'(context

Re: delegates with C linkage

2010-06-06 Thread bearophile
Zarathustra: > I think there is a good chance for create the set examples which show how to > use D > features on the C level. I will thinking about it in my free time :) The idea > is > really interesting and it would be useful(especially to better understand > these > mechanisms) for some peop

Re: delegates with C linkage

2010-06-06 Thread Zarathustra
> my fault - yes its possible to use delegates in non D but delegat-struct > knowing languages (and a small pice of special calling code), sorry > Zarathrustra i missed the point of your post in whole No problem, I'm glad that we have reached an agreement. > wouldn't it be nice to have an complete

Re: delegates with C linkage

2010-06-06 Thread dennis luehring
Am 06.06.2010 11:33, schrieb Simen kjaeraas: Also, pointers to delegates can be passed to C-linkage functions. A delegate is nothing but a struct, and as such there is no reason for it not to be passable to a C-linkage function. my fault - yes its possible to use delegates in non D but delegat-

Re: delegates with C linkage

2010-06-06 Thread Simen kjaeraas
dennis luehring wrote: D still won't accept an delegat in an extern C because this type does not exists in the C world Nor do classes, and those certainly can be passed to a C-linkage function. Also, pointers to delegates can be passed to C-linkage functions. A delegate is nothing but a str

Re: delegates with C linkage

2010-06-05 Thread Zarathustra
> but that will help on the caller side (you using gcc?) but D still won't > accept an delegat in an extern C because this type does not exists in > the C world Maybe it is the reason but the error message is still nonsense. > btw: can show us code where you do this and it works - why don't you us

Re: delegates with C linkage

2010-06-05 Thread dennis luehring
Am 05.06.2010 16:03, schrieb dennis luehring: Am 05.06.2010 15:42, schrieb Zarathustra: only with static methods - a real delegate needs the this-pointer in a register (not on the stack), thats the main difference between function ptr and delegates, thats why you can't use a (non static) m

Re: delegates with C linkage

2010-06-05 Thread dennis luehring
Am 05.06.2010 15:42, schrieb Zarathustra: only with static methods - a real delegate needs the this-pointer in a register (not on the stack), thats the main difference between function ptr and delegates, thats why you can't use a (non static) method on for example the win-api callbacks, becau

Re: delegates with C linkage

2010-06-05 Thread Zarathustra
> only with static methods - a real delegate needs the this-pointer in a > register (not on the stack), thats the main difference between function > ptr and delegates, thats why you can't use a (non static) method on for > example the win-api callbacks, because the caller don't know your object gc

Re: delegates with C linkage

2010-06-05 Thread dennis luehring
Am 05.06.2010 13:33, schrieb Zarathustra: Secondly, I'm not sure if you can pass delegates to a C function. C code wouldn't understand delegates. They are not the same as function pointers. I suggest you use function pointers instead, paying attention to linkage. Of course It is possible, b

Re: delegates with C linkage

2010-06-05 Thread Zarathustra
> For starters, your first delegate is declared in an extern(C) block, > meaning it has C linkage. The second is declared outside of the block, > meaning it has D linkage. So they are two different types of delegates. What is the difference? > Secondly, I'm not sure if you can pass delegates to a

Re: delegates with C linkage

2010-06-05 Thread Simen kjaeraas
Mike Parker wrote: For starters, your first delegate is declared in an extern(C) block, meaning it has C linkage. The second is declared outside of the block, meaning it has D linkage. So they are two different types of delegates. If this is correct, the problem should be fixable by writin

Re: delegates with C linkage

2010-06-04 Thread Mike Parker
Zarathustra wrote: I have obtained a strange error message when I tried to use delegate as an argument in a C linkage function. private extern (C) static { void d_foo_add_event_handler(Foo, void delegate()); } class Foo { void addEventHandler(void delegate() handler) { d_foo_add_event_h

delegates with C linkage

2010-06-04 Thread Zarathustra
I have obtained a strange error message when I tried to use delegate as an argument in a C linkage function. private extern (C) static { void d_foo_add_event_handler(Foo, void delegate()); } class Foo { void addEventHandler(void delegate() handler) { d_foo_add_event_handler(this, handler)