mangling of extern(C) members

Adam D. Ruppe destructionator at gmail.com
Fri Jan 11 06:27:32 PST 2013


bottom line up front: I want pragma(mangle, "name")

I'd like to be able generate references to other functions in 
templates and stuff


mixin template Template() {
         extern(C) void test(); /* I want this to call test() */
}

struct Test {
         mixin Template!();
         void mything() { test(); }
}



Why is it useful? Previously I've wanted to play with generating 
C calls with opDispatch, and today I was thinking we could 
generate C++ interfacing this way.

dmd can call a great deal of C++ already, but it doesn't include 
constructors. We can work around it:

extern(C) void _ZN5ClassC1Ev(Class* c); // the C++ constructor
Class c;
_ZN5ClassC1Ev(&c);

and what would be nice is to be able to mixin some function that 
could generate that mangle automatically and call it for us.



A solution to this specific thing is to add C++ constructor 
mangling to the extern(C++) support.

But I think the general solution is pragma(mangle), that's been 
discussed before.


More information about the Digitalmars-d mailing list