开发者

Is C++ name mangling (decoration) deterministic?

I hope to LoadLibrary on an unmanaged C++ DLL with managed code, and then call GetProcAddress on extern functions which have been mangled. My question is are the mangled names you get from a C++ compiler det开发者_如何学运维erministic? That is: Will the name always by converted to the same mangled name, if the original's signature hasn't changed?


It isn't specified by the standard, and has certainly changed between versions of the same compiler in my experience, though it has to be deterministic over some fixed set of circumstances, because otherwise there would be no way to link two separately compiled modules.

If you're using GetProcAddress, it would be far cleaner to export the functions as extern "C" so their names are not mangled.


It's compiler specific, as others have said. However, you can find details in a document by Agner Fog...

http://www.agner.org/optimize/#manuals

See item 5 on that page.

Also, these days, there are libraries which can handle mangling and demangling for common compilers for you. For Visual C++, the starting point would be the dbghelp and imagehlp libraries.

http://msdn.microsoft.com/en-us/library/ms679292%28v=VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms680321%28v=VS.85%29.aspx


Name mangeling is handled differently by every compiler (maybe or not-there is no standard). If you use pure C functions in your C++ code, you can use the extern "C" to supress name mangeling for the C functions so the compiler is able to find them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜