Thread overview
[Issue 4288] New: Error on passing delegate to C linkage function.
Jun 06, 2010
Adam Chrapkowski
Jun 06, 2010
Robert Clipsham
Jun 06, 2010
Adam Chrapkowski
May 12, 2012
klickverbot
May 13, 2012
Walter Bright
June 06, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4288

           Summary: Error on passing delegate to C linkage function.
           Product: D
           Version: 1.057
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: adam.chrapkowski@gmail.com


--- Comment #0 from Adam Chrapkowski <adam.chrapkowski@gmail.com> 2010-06-06 09:24:38 PDT ---
Error occurs, when you try to use a delegate as a parameter to a C linked function.

ex:
extern (C)
void c_func(void delegate() dg);
void d_func(void delegate() dg) { c_func(dg); }

Error: function test.c_func (void delegate()) does not match parameter types
(void delegate())
Error: cannot implicitly convert expression (dg) of type void delegate() to
void delegate()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 06, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4288


Robert Clipsham <robert@octarineparrot.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |robert@octarineparrot.com


--- Comment #1 from Robert Clipsham <robert@octarineparrot.com> 2010-06-06 17:59:33 BST ---
I don't think this bug is valid, something does need to be done about it though. The following works:
----
alias extern(C) void delegate() cdg;
extern (C)
void c_func(void delegate() dg);
void d_func(cdg dg) { c_func(dg); }
----
So the problem is the linkage of the delegates doesn't match, there's no way to get around it without an alias though, you can't have extern(C) in the function parameters. Either the error needs improving, or there needs to be a way to specify the linkage in the function args.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 06, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4288



--- Comment #2 from Adam Chrapkowski <adam.chrapkowski@gmail.com> 2010-06-06 11:11:41 PDT ---
So two questions:

1. Why the following is allowed:
extern (C) void c_func(void delegate());
?

2. What does mean extern (C) void delegate() ?

Delegate is just a 'data structure which consists of two pointers' and anything more. Something like C delegate does not exists. Linkage is related to functions not data structures delegate is a data structure.

So if D data structures are disallowed in C functions why the following is
allowed?
extern (C) void c_func(string, Foo);
class Foo{...}
void d_func() {
  scope  foo = new Foo();
  string str = "Hello World!";
  c_func(str, foo);
}

string is a data structure as delegate, foo is a pointer to a data structure.

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


klickverbot <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@klickverbot.at


--- Comment #3 from klickverbot <code@klickverbot.at> 2012-05-12 07:40:25 PDT ---
Error message fix:

https://github.com/D-Programming-Language/dmd/pull/943

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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