Call a function with a function pointer

Dicebot public at dicebot.lv
Thu Oct 10 08:56:43 PDT 2013


On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote:
> Namespace:
>
>> You mean like this?
>> ----
>> void foo(T)(extern(C) void function(T*) func) {
>> 		
>> }
>> ----
>>
>> That prints: Error: basic type expected, not extern	
>
> In theory that's correct, in practice the compiler refuses 
> that, it's in Bugzilla, so try to define the type outside the 
> signature (untested):
>
> alias TF = extern(C) void function(T*);
>
> void foo(T)(TF func) {}
>
> Bye,
> bearophile

That is limitation of current extern - it can only be attached to 
symbol declarations, not types. AFAIK you need to do `extern(C) 
alias TF = ...` but anyway this method is very likely to break 
IFTI completely.



More information about the Digitalmars-d-learn mailing list