Question about function aliases

FreeSlave freeslave93 at gmail.com
Thu Dec 12 03:39:54 PST 2013


On Thursday, 12 December 2013 at 11:11:55 UTC, bearophile wrote:
> Gary Willoughby:
>
>> alias void function(ClientData clientData, Tcl_Interp* interp)
>>  Tcl_InterpDeleteProc;
>>
>> extern (C) void Tcl_CallWhenDeleted(Tcl_Interp* interp, 
>> Tcl_InterpDeleteProc proc, ClientData clientData);
>
> With recent D compilers I prefer the alias with "=" and a more
> aligned colums formatting of the arguments when they don't fit
> well in a line:
>
>
> alias Tcl_InterpDeleteProc = void function(ClientData 
> clientData,
> Tcl_Interp* interp);
>
> extern(C) void Tcl_CallWhenDeleted(Tcl_Interp* interp,
>                                     Tcl_InterpDeleteProc proc,
>                                     ClientData clientData);
>
> Also, can't you add some "const" in those arguments? Is your C
> function pure? It should be nothrow.
>
> Bye,
> bearophile

I guess alias also should include extern(C) declaration i.e. the 
right way is
alias Tcl_InterpDeleteProc = extern(C) void function(ClientData 
clientData, Tcl_Interp* interp) nothrow;

So your callback on D side must have C-linkage too.
Lack of extern(C) in alias probably will not cause problem on 
Linux, but in my experience, Windows requires it otherwise you 
will get seg fault.


More information about the Digitalmars-d-learn mailing list