extern(C) names are being mangled; that's crazy, Walter says I'm crazy

Ethan gooberman at gmail.com
Wed Jul 24 23:03:28 UTC 2019


On Wednesday, 24 July 2019 at 21:32:11 UTC, Manu wrote:
> You write `extern(C) void fun();`, you expect a function called 
> "fun",
> not "_D9__mixin153funv"

Yes, that's what I expect. The similar problem I had with 
extern(C++) was that I should have expected it. extern(C++) works 
as expected but extern(C) doesn't? Strange things are afoot at 
the Circle K...

> The rule is "extern(C) might mean what you want, and if it 
> doesn't, we
> recommend you use pragma(mangle) to reconstruct the C symbol 
> name...
> but don't forget to check if you need an underscore!"

And this is what Binderoo is doing. In a roundabout way, that is. 
Defining extern(C) and extern(C++) everywhere gets in the way of 
just writing D code, so Binderoo generates C and C++ wrappers. 
Bonus with this approach: inlining is preserved.

(Got some almost-finished code to correctly make C++ mangles for 
templated types, works for basically everything else so static 
linking should Just Work(TM) ).


More information about the Digitalmars-d mailing list