Declaring a D pointer to a C function

Johannes Pfau spam at example.com
Tue Jul 12 06:50:18 PDT 2011


Trass3r wrote:
>> You should declare the function pointer without the "extern(C)".
>>
>> Example:
>> alias int function(void* test) FTInitFunc;
>>
>> extern(C) int foo(void* test){ .... }
>>
>> FTInitFunc foo_ptr = &foo;
>>
>> This worked for me.
>
>That's a bug.

I agree. It looks like the above code assigns a extern(C) function
pointer to a field which should only accept D function pointers.
I guess if you then call foo_ptr dmd will use the D calling convention
and that'll crash, at least for more complicated functions.

-- 
Johannes Pfau



More information about the Digitalmars-d-learn mailing list