C++/C mangleof inconsistency for OS X

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 21 11:29:36 PDT 2015


On 2015-04-21 19:01, Dan Olson wrote:

> Hmmm, I can see another point of view where mangleof should produce the
> equivalent extern(C) symbol.  My gut says this is the way it should
> work.

That makes sense.

> If I want to call a C function void debug(const char*) from a C library,
> I would do this because of D "debug" keyword:
>
>    pragma(mangle, "debug")
>    extern (C) void debug_c(const(char*));
>
> Now I would think debug_c.mangleof -> "debug"
> (and that is indeed what dmd produces even on OS X).

Are there use cases where one would want to use some other mangling than 
C? I mean, D is a system programing language.

> On systems which prepend an underscore, we want compiler to take care of
> this so code is portable, otherwise code must do this:
>
> version (OSX)
>    pragma(mangle, "_debug") extern (C) void debug_c(const(char*));
> else
>    pragma(mangle, "debug") extern (C) void debug_c(const(char*));

These are all good points.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list