On Wednesday, 11 December 2013 at 23:42:44 UTC, Gary Willoughby wrote:
For example i have some C code like this:

typedef void (Tcl_InterpDeleteProc) _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp));

void Tcl_CallWhenDeleted(Tcl_Interp* interp, Tcl_InterpDeleteProc* proc, ClientData clientData);


I intend on converted this to D thus:

alias void function(ClientData clientData, Tcl_Interp* interp) Tcl_InterpDeleteProc;

void Tcl_CallWhenDeleted(Tcl_Interp* interp, Tcl_InterpDeleteProc* proc, ClientData clientData);

Is it correct keeping the * with the Tcl_InterpDeleteProc parameter or do i remove it? Is the alias above a function pointer?

To call this function can i use a function literal for the Tcl_InterpDeleteProc parameter? or do i need to pass an address of the function?

It's a function pointer.
Test:

import std.stdio;
alias extern(C) void function(void*) Callback;

void Call(Callback c)
{
    c(c);
}

extern(C) void callback(void* v)
{
    writefln("v: %04X", v);
}
        
void main()
{
    Callback c = &callback;
    Call(c);    
    writefln("c: %04X", c);
}

Reply via email to