www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6754] New: extern() in a function signature

reply d-bugmail puremagic.com writes:
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



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: -------
Oct 01 2011
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Oct 16 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6754




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: -------
Dec 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6754


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

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



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: -------
Aug 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6754




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: -------
Oct 10 2013