Comment #0 by bearophile_hugs — 2011-10-01T17:22:06Z
This comes from code shown in D.learn:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=29886
You can't use extern(C) in a function signature:
void foo(extern(C) void function() f) {}
void main() {}
DMD 2.056head gives:
test.d(1): basic type expected, not extern
test.d(1): found 'extern' when expecting ')'
test.d(1): semicolon expected following function declaration
test.d(1): Declaration expected, not '('
Workaround: before the function definition you have to define the argument type with an alias:
alias extern(C) void function() CF;
void foo(CF f) {}
void main() {}
Comment #1 by andrej.mitrovich — 2012-10-16T11:20:40Z
Since @safe is already allowed I don't see why extern() shouldn't be allowed:
void test(void function() @safe) { } // compiles
There are workarounds e.g. using uniquely-named aliases or module-scope extern(C): declaration, the latter is a bit odd since the attribute ends up affecting parameters and not just declarations in module scope.
Walter can we get an OK to implement this enhancement? Allowing the enhancement would be beneficial for binding with C:
extern(C) void test(extern(C) void function() callback);
Comment #2 by andrej.mitrovich — 2012-12-27T16:15:04Z
Someone mentioned in IRC they've already implemented this. To the person that did: please provide a patch (or a pull) so we don't duplicate our efforts, thanks.
Comment #3 by andrej.mitrovich — 2013-08-17T07:54:52Z
*** Issue 10837 has been marked as a duplicate of this issue. ***
Comment #4 by bearophile_hugs — 2013-10-10T13:26:36Z
Another example:
alias extern(C) void function() TF1; // OK
alias TF2 = extern(C) void function(); // Error
void main() {}
test.d(2): Error: basic type expected, not extern
test.d(2): Error: semicolon expected to close alias declaration
test.d(2): Error: no identifier for declarator extern (C) void function()
Comment #5 by robert.schadek — 2024-12-13T17:56:36Z