C++/C mangleof inconsistency for OS X
Michel Fortin via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 21 13:50:53 PDT 2015
On 2015-04-21 18:29:36 +0000, Jacob Carlborg <doob at me.com> said:
> On 2015-04-21 19:01, Dan Olson wrote:
>
>> 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.
Apple does this in many of its own C headers. Lookup the definition of
pthread_join for instance, you'll see the __DARWIN_ALIAS macro which
when expanded under certain circumstances adds a suffix to the symbol
name in a similar way to pragma(mangle) in D. This allows some fixes to
only apply to code compiled with newer SDKs. (Also note that the
underscore is explicitly put there by the macro.)
--
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca
More information about the Digitalmars-d
mailing list