alias and extern(C)

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 30 11:43:19 PDT 2014


Hi.

I am trying to translate the following from the Dart header:
typedef void (*Dart_MessageNotifyCallback)(Dart_Isolate 
dest_isolate);

So I made a little simple test to understand callbacks in D.  The 
code below works fine if you remove the extern(C).  But I get the 
error "functionpointertest.d(6): Error: basic type expected, not 
extern" with the code as it  is.

How do I use alias with extern ?

Thanks.


Laeeth.

import std.stdio;
// test_typedef.d

//typedef void (*Dart_MessageNotifyCallback)(Dart_Isolate 
dest_isolate);

alias Callback= extern(C) void function(int);

extern(C) void testfn(int i)
{
	writefln("%s",i+1);
	return;
}

extern(C) void testfn2(int i)
{
	writefln("%s",i*i);
	return;
}

void foo(Callback callback)
//void foo(void function(int) callback)
{
	callback(100);
	//callback(101);
}

void main()
{
	foo(&testfn);
	foo(&testfn2);
}


More information about the Digitalmars-d-learn mailing list