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

Manu turkeyman at gmail.com
Wed Jul 24 21:32:11 UTC 2019


On Wed, Jul 24, 2019 at 7:20 AM Ethan via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Wednesday, 24 July 2019 at 05:03:16 UTC, Manu wrote:
> > https://issues.dlang.org/show_bug.cgi?id=20012
> >
> > I need to know who is the crazy one here?
> > I can't believe the idea that extern(C) functions being mangled
> > to
> > un-knowable generated names is what any sane user would ever
> > expect.
> >
> > Surely extern(C) means extern(C)?
> >
> > I'd like a poll here...
>
> I've only glanced at the thread last night through red eyes.
>
> But on Windows. Because most of my mangling experience is on
> Windows.
>
> If you extern( C ) and it doesn't get mangled to exactly the
> __traits( identifier ) and nothing else then it's being done
> wrong.
>
> You get duplicate symbols? Tough.
>
> I had a similar problem at Remedy with trying to use named
> modules and Binderoo to invoke a commonly named extern( C++ )
> function. And of course all those functions were mangled exactly
> the same because it's extern( C++ ) and there's no parent
> namespace. I mentioned this in my DConf 2018 talk. My solution is
> outside of the scope of this thread.

Yeah, that's not what we're talking about.
Stuff needs to do the right and proper thing, and when that's not what
we want, we need power to override it.

This is a case where extern(C) does weird shit that nobody would ever
expect, and I'm being told to use the override to do the default
thing.
You write `extern(C) void fun();`, you expect a function called "fun",
not "_D9__mixin153funv", why would anyone expect extern(C) to emit a D
function? You can't write that in a `.h` file; the `15` on the end of
"mixin" is a random serial number, it's impossible to know the
function name, you literally can't declare it in a '.h' file!

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!"


More information about the Digitalmars-d mailing list