Thread overview
[Issue 6754] New: extern() in a function signature
Oct 16, 2012
Andrej Mitrovic
Dec 28, 2012
Andrej Mitrovic
Aug 17, 2013
Andrej Mitrovic
October 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6754

           Summary: extern() in a function signature
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2011-10-01 17:22:06 PDT ---
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() {}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 16, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6754


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-16 11:20:40 PDT ---
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);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6754



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-27 16:15:04 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 17, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6754


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |weltensturm@gmail.com


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-08-17 07:54:52 PDT ---
*** Issue 10837 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6754



--- Comment #4 from bearophile_hugs@eml.cc 2013-10-10 13:26:36 PDT ---
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()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------