www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11379] New: Cannot combine calling convention with an existing alias

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11379

           Summary: Cannot combine calling convention with an existing
                    alias
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-10-29
11:14:59 PDT ---
I think this may be a dupe but I can't find the report:

-----
void main()
{
    alias Foo = int function(int);

    // workaround
    mixin("alias extern(C) " ~ Foo.stringof ~ " C_Foo;");

    // ok
    static assert(!is(C_Foo == Foo));

    // non-mixin version
    alias extern(C) Foo C_Foo2;

    // fails
    static assert(!is(Foo == C_Foo2));
}
-----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 29 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11379



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-10-29
11:17:04 PDT ---
A use-case could be to apply a linkage from a source function type to a target
function type, for example:

-----
import std.string;
import std.traits;

template ApplyLinkage(Source, Target)
{
    enum link = functionLinkage!Source;

    mixin(q{
       alias extern(%s) %s ApplyLinkage;
    }.format(link, Target.stringof));
}

extern(C) void foo() { }

void main()
{
    alias Bar = int function(int);
    Bar bar;

    alias C_bar = ApplyLinkage!(typeof(foo), Bar);
    C_bar cBar;

    Bar func;
    func = bar;   // ok, succeeds
    func = cBar;  // ok, fails
}
-----

Currently the .stringof trick is necessary due to this bug.

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