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

Manu turkeyman at gmail.com
Sat Jul 27 04:58:38 UTC 2019


On Fri, Jul 26, 2019 at 8:10 PM Ethan via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Friday, 26 July 2019 at 21:34:29 UTC, Manu wrote:
> > I'm pretty sure it's about both
>
> 100% this.
>
> D can't claim complete 100% C interoperability if it can't
> generate symbols that a C compiler expects to find.

It obviously can, it's just a really weird edge case. The reason is
that it turns out mixin introduces a named scope; something that I
think 99% of people have no idea about, and I'm not sure is helpful.
If mixin doesn't mean mixin, but rather "mix nearby then alias", I
don't find that intuitive.
Every mixin I've ever written, I author it in such a way that if it
were to be used multiple times in the same scope, I handle that if
it's designed to work that way, or I produce an error. I bet everyone
does this?
I also expect that if I wanted to make colliding symbols in the same
scope, I could do that too. I don't love that mixin creates a scope,
it seems weird and pointless and possibly easy to accidentally hide
stuff by mistake... If I wanted a scope, I'd put a scope in my mixin.
I don't believe anyone would expect this.

But in particular, the idea that mangling doesn't work because a
function is in a mixin; that's just too surprising to accept.

> export extern(C++) void fun() {}
>
> AND
>
> mixin template M()
> {
>    export extern(C++) void fun() {}
> }
> mixin M!();
>
> You know what pragma( msg, fun.mangleof ) prints for both of them?
>
> The exact same symbol, of course. _Z3funv on Linux, ?fun@@YAXXZ
> on Windows.

Oh really? Serious?
Yeah, this is just a plain straight-up bug. There's no excluse for this.

> Looking through the bug report. "You can get the behaviour you
> wanted with this code hack." No. This *cannot* be the face of the
> D language. Simple stuff like this should Just Work(TM).

Right, you don't move to a shiny new futuristic modern language so you
can start writing weird work-arounds that I can't explain to people on
day-one... it really does make a very bad impression.


More information about the Digitalmars-d mailing list