delegates with C linkage

Zarathustra adam.chrapkowski at
Fri Jun 4 13:43:29 PDT 2010

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);
Error: function foo.d_foo_add_event_handler(Foo, void delegate()) does not
match parameter types (Foo, void delegate())
Error: cannot implicitly convert expression (handler) of type void delegate()
to void delegate()
The second error message is especially extreme.

When I use:
  struct DelegateVoid { void* ptr, funcptr; } // void delegate() ABI
  void d_foo_add_event_handler(Foo, DelegateVoid);
  d_foo_add_event_handler(this, *cast(DelegateVoid*)&handler);

Everything works well but I still have no idea why I cannot implicitly use

More information about the Digitalmars-d-learn mailing list