Can't assign extern(C) function pointer to D variable?

XavierAP n3minis-git at yahoo.es
Tue Nov 22 21:11:37 UTC 2022


I was surprised when it didn't compile, though I immediately 
found it understandable...
Already read through https://dlang.org/spec/interfaceToC.html
and https://wiki.dlang.org/Bind_D_to_C

Is it really the case (that an extern(C) function pointer cannot 
be assigned to a D variable)? Or is it a matter of annotating 
with the right attributes? If so, how?

Otherwise I'm interested in the best or most concise workaround. 
Is there a better one? I came up with a template solution:

https://github.com/XavierAP/game-king/blob/master/source/scope_cleanup.d

The problem I had was that this ScopeCleanup struct could not be 
constructed passing a pointer to a function imported from C (from 
the SDL library; you can browse around the same repo to see its 
usage; it's just a toy project that's barely started).


More information about the Digitalmars-d-learn mailing list