我可以解密 GCC 的 RTTI 名称吗?

发布于 2024-08-18 04:59:28 字数 178 浏览 2 评论 0原文

使用 gcc,当我使用 typeid 请求对象/变量的类型时,我从 type_info::name 方法得到的结果与我期望在 Windows 上得到的结果不同。我用 Google 搜索了一下,发现 RTTI 名称是特定于实现的。

问题是,我想获取类型的名称,因为它将在 Windows 上返回。有没有简单的方法可以做到这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

窝囊感情。 2024-08-25 04:59:28

如果这就是您所要求的,那么就 type_info::name() 返回的名称而言,没有编译器开关可以使 gcc 的行为类似于 msvc。

但是,在您的代码中,您可以依赖 gcc 特定的 __cxa_demangle 函数。

事实上SO 的答案可以解决您的问题

参考:libstdc++ 手册,第 40 章。分解

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.

梦醒时光 2024-08-25 04:59:28

C++ 函数名称实际上包括所有返回和参数类型信息以及类和方法名称。编译时,它们被“破坏”成标准形式(每个编译器的标准),可以充当汇编程序符号并包含所有类型信息。

您需要运行一个函数或程序来逆转这种损坏,称为demangler

尝试

c++filt myoutput.txt

在函数的输出上运行。这将真实的符号名称分解回人类可读的形式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文