Optional name mangling

Mike Parker aldacron at gmail.com
Sat Jul 21 19:32:54 PDT 2012


On 7/22/2012 4:24 AM, Stuart wrote:
> Hi. Is there any way to instruct the D compiler not to use name mangling
> when referencing an external C++ function?
>
> For example:
>
>     extern (System) bool PathRenameExtension(LPSTR pszPath, LPCSTR pszExt);
>
> In this particular case, the exported function being referenced is not
> called _PathRenameExtension at 8 - it's just called PathRenameExtension.
> Now, it's great that D helpfully mangles the name for me when
> appropriate, but we really need some way to disable it when necessary.
>
> Is there any way to import this function without creating a .def file
> with "_PathRenameExtension at 8 = PathRenameExtension"? And if not, why not?

extern(System) is extern(Windows) on Windows and extern(C) everywhere else.

extern(Windows) is stdcall, which is the Win32 API calling convention. 
stdcall function names are mangled to _funcName at N. So extern(System) is 
doing the right thing here.

What's odd is that your PathRenameExtension isn't mangled.


More information about the Digitalmars-d mailing list