Frontend and backend communication

Dainius (GreatEmerald) pastas4 at gmail.com
Tue Nov 29 03:53:19 PST 2011


I seem to have another problem with the function pointer approach. I
am trying to set up a function that would pass the function pointers
from C to D, and DMD refuses to compile it:

If I have the function pointer struct with D calling convention
pointers, like this:

    struct S_FrontendFunctions {
        void function(int) SoundPlay;
        void function() RedrawScreen;
    }
    S_FrontendFunctions FrontendFunctions;

And I try to set it in D like this:

    FrontendFunctions.SoundPlay = function(int){};
    FrontendFunctions.RedrawScreen = function(){};

And have a function for transferring the pointer from C like this:

    extern (C):
    void SetRedrawScreen(void function() RedrawScreen)
    {
        FrontendFunctions.RedrawScreen = RedrawScreen;
    }

DMD throws an error in the last function:

    Error: cannot implicitly convert expression (RedrawScreen) of type
extern (C) void function() to void function()

Now if I define the two function pointers as extern(C) like this:

    struct S_FrontendFunctions {
        extern (C) void function(int) SoundPlay;
        extern (C)  void function() RedrawScreen;
    }

DMD still complains, but this time about when I set the pointers from
D directly:

    Error: cannot implicitly convert expression (__funcliteral3) of
type void function() pure nothrow @safe to extern (C) void function()

Any ideas about how to make it work from both D and C sides?


More information about the Digitalmars-d-learn mailing list