Exporting template function instances to C

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 23 10:58:21 PDT 2017


On Thu, Mar 23, 2017 at 05:29:22PM +0000, data pulverizer via Digitalmars-d-learn wrote:
> On Thursday, 23 March 2017 at 16:38:02 UTC, Adam D. Ruppe wrote:
> > On Thursday, 23 March 2017 at 16:28:18 UTC, data pulverizer wrote:
> > > alias mult!double dmult;
> > > alias mult!float fmult;
> > 
> > Those are just aliases in the D compiler, they don't actually exist
> > in the object file for C to use like regular functions.
> > 
> > Templates need to actually be *used* to be instantiated for export,
> > and aliases make them easier to use, but don't actually use them
> > yet.
[...]
> 
> Thanks. Is there a less ham-handed way of exporting them other than
> wrapping them in functions as I have?

Wrapping them in functions is probably the simplest way to call them
from C.  You *could*, I suppose, use their mangled names directly, then
you wouldn't need a wrapper, but that would be rather difficult to use
on the C end.  On the D side, there's .mangleof that will tell you what
mangled names to use, but if you're calling from C you don't have that
luxury.


T

-- 
People who are more than casually interested in computers should have at
least some idea of what the underlying hardware is like. Otherwise the
programs they write will be pretty weird. -- D. Knuth


More information about the Digitalmars-d-learn mailing list