int C function

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Oct 1 06:33:04 PDT 2011


On 10/1/11, Ellery Newcomer <ellery-newcomer at utulsa.edu> wrote:
> On 09/30/2011 08:20 PM, Andrej Mitrovic wrote:
>> I think this is a side-effect of the new function pointer fixes, where
>> you now can't implicitly convert an extern(C) function to an extern(D)
>> function by accident (and that's a good thing). But the problem is,
>> you can't define a function with a different linkage type inline as a
>> type parameter. You have to use an alias instead:
>
> wait, are there explicit ways to convert extern(C) funcs <-> extern(D)
> funcs?
>

You can convert anything with an explicit cast, but it doesn't make
much sense to cast between calling conventions types. The compiler
used to allow taking an address of an extern(C) function and assigning
it to an extern(D) function pointer. But this would just result in
segfaults and memory corruption due to how parameters are passed.

Nice code-golf, btw.


More information about the Digitalmars-d-learn mailing list