Callbacks and interfacing with C

Jacob Carlborg doob at me.com
Tue Oct 30 12:35:06 PDT 2012


On 2012-10-30 18:44, Andrej Mitrovic wrote:

> All of them.
>
> void main()
> {
>      pragma(msg, MyFn);
>      pragma(msg, typeof(MyStruct.foo2));
>      pragma(msg, typeof(bar));
> }
>
> extern (C) int function(int)
> extern (C) int function(int)
> extern (C) void(extern (C) int function(int) foo3)
> extern (C) int function(int)
> extern (C) int function(int)
> extern (C) void(extern (C) int function(int) foo3)
>
> It's because extern(C): leaks everywhere, whether on purpose or not.
> It can be a benefit for writing shorter code, but when reading such
> code it's easy to forget to check for an extern(C): declaration at the
> top and just wrongly assume that it's all extern(D).

It doesn't leak into local declarations in a function:

extern (C):

void foo ()
{
     alias void function () Foo;

     void function (int) a;
     auto b = cast(void function ()) a;

     pragma(msg, Foo);
     pragma(msg, typeof(a));
     pragma(msg, typeof(b));
}

void function()
void function(int)
void function()

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list