Wrapping C APIs in D functions of same name?

Rick Mann rmann-d-lang at latencyzero.com
Sun Jan 28 10:52:21 PST 2007


Tyler Knott Wrote:

> Yes.  Because module imports can be declared as "private" (and are by 
> default), you can simply write two seperate modules.  One would contain 
> all the extern (C) declarations, and the other containing the D 
> wrappers.  The module with the wrappers would import the module with the 
> externs (privately), and call the extern functions using the fully 
> qualified name of them (e.g. in a module foo.bar with a function func 
> taking (param), you'd call it as foo.bar.func(param)).

Of course; I should've thought of this.

I guess, though, there's no way to do it with a single module, right? 

Will the approach above result in link errors when I link my D program against the C library? Or does the D name mangling make the D symbol name different than the C name? Does the D-linkage mangling include the module name?


More information about the Digitalmars-d-learn mailing list