Thread overview
alias and extern(C)
Oct 30, 2014
Laeeth Isharc
Oct 30, 2014
anonymous
Oct 30, 2014
Laeeth Isharc
October 30, 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);
}
October 30, 2014
On Thursday, 30 October 2014 at 18:43:21 UTC, Laeeth Isharc wrote:
> 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 ?
[...]
> alias Callback= extern(C) void function(int);

Compiles as is with dmd 2.066. For 2.065 and older you have to
put extern(C) in front of "alias":

extern(C) alias Callback= void function(int);
October 30, 2014
>> 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 ?
> [...]
>> alias Callback= extern(C) void function(int);
>
> Compiles as is with dmd 2.066. For 2.065 and older you have to
> put extern(C) in front of "alias":
>
> extern(C) alias Callback= void function(int);

Many thanks, anon.

You are right - I was running older dmd on this machine.  It works fine with your modification, as you suggest.


Laeeth.