Can I ungarble GCC's RTTI names?

此生再无相见时 提交于 2019-12-19 07:23:44

问题


Using gcc, when I ask for an object/variable's type using typeid, I get a different result from the type_info::name method from what I'd expect to get on Windows. I Googled around a bit, and found out that RTTI names are implementation-specific.

Problem is, I want to get a type's name as it would be returned on Windows. Is there an easy way to do this?


回答1:


If it's what you're asking, there is no compiler switch that would make gcc behave like msvc regarding the name returned by type_info::name().

However, in your code you can rely on the gcc specific __cxa_demangle function.

There is in fact an answer on SO that addresses your problem.

Reference: libstdc++ manual, Chapter 40. Demangling.




回答2:


c++ function names really include all the return and argument type information as well as the class and method name. When compiled, they are 'mangled' into a standard form (standard for each compiler) that can act as an assembler symbol and includes all the type information.

You need to run a function or program to reverse this mangling, called a demangler.

try running

c++filt myoutput.txt

on the output of the function. This demangles the real symbol name back into a human readable form.




回答3:


Based on this other question Is there an online name demangler for C++? I've written a online tool for this: c++filtjs



来源:https://stackoverflow.com/questions/2085239/can-i-ungarble-gccs-rtti-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!