digitalmars.D.learn - alias and extern(C)
- Laeeth Isharc (37/37) Oct 30 2014 Hi.
- anonymous (5/10) Oct 30 2014 Compiles as is with dmd 2.066. For 2.065 and older you have to
- Laeeth Isharc (4/14) Oct 30 2014 Many thanks, anon.
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); }
Oct 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);
Oct 30 2014
Many thanks, anon. You are right - I was running older dmd on this machine. It works fine with your modification, as you suggest. Laeeth.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);
Oct 30 2014