[Issue 20012] export inside mixin doesn't seem to work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 24 21:13:28 UTC 2019


--- Comment #18 from Manu <turkeyman at gmail.com> ---
> Callbacks are more common than reflection-based dll exports.

This is about what extern(C) means.
mixin is supposed to inject code into the lexical scope it's mixed into. If you
mixin to the global scope, it should be in the global scope, and there's
nothing to mangle with.
What we've learned here is that mixin is like some form of namespace, and
that's NOT written on the tin, and definitely not what I have ever wanted.
I bet almost nobody knows this, and they craft their mixins to work assuming
they that they are inserted into the scope they're mixed into.

This is also the part that doesn't make sense, an extern(C) function at global
scope should be an extern(C) function, even if you want to make the rule that a
nested one would be mangled somehow (since a nexted extern(C) function is kinda
invalid anyway), the global scoped function should be as you expect.

Callbacks nested in some scope are the thing that's distinctly not-C, and in
that scenario the name is effectively anonymous anyway, it could be anything.
That should be where you use the pragma(mangle) trick, with any string you
like, because it doesn't matter; `pragma(mangle, makeAnonName())`.

extern(C) should mean extern(C), and this case of "I half-want extern(C)" can
be deliberately achieved with pragma(mangle).

> Also wouldn't you want to export them without the leading underscore?

It depends on the ABI. To use pragma(mangle), you need to determinate the ABI
details and mangle with or without the underscore accordingly.


More information about the Digitalmars-d-bugs mailing list