C++/C mangleof inconsistency for OS X

Dan Olson via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 22 09:32:55 PDT 2015


Michel Fortin <michel.fortin at michelf.ca> writes:
>
> I think if you specify the mangling most of the time it's because you
> don't want the compiler to do it for you. But you should consider
> doing this:
>
> string mangleC(string name) {
> 	version (OSX) return "_" ~ name;
> 	else return name;
> }
>
> pragma(mangle, mangleC("debug")) extern (C) void debug_c(const(char*));

I found that exists as core.demangle.mangleC() does exactly that, just
added last fall.

Since the compile chain knows whether the target system prepends an
underscore, I wonder if it can be bubbled up into some compiler trait or
version that prevents writing versioned code based on system.  I think
it would help gdc much as it has many targets, and many prepend
underscore to symbols.  It would help with unittests like
compilable/cppmangle.d that would have to be tailored for every OS.
that uses gcc3 style C++ mangling.


More information about the Digitalmars-d mailing list