Home >Backend Development >C++ >How Can I Demangle GCC\'s Mangled Type Names from typeid.name()?

How Can I Demangle GCC\'s Mangled Type Names from typeid.name()?

Barbara Streisand
Barbara StreisandOriginal
2024-11-26 06:04:09622browse

How Can I Demangle GCC's Mangled Type Names from typeid.name()?

Demangling Unmangled Type Names with typeid.name() in GCC

When utilizing typeid.name() to retrieve the name of a type, different compilers may provide varying results. For instance, GCC is known to return a "mangled" name, while Visual C delivers an unmangled name.

This discrepancy stems from the fact that typeid.name()'s return value is implementation-defined. As per the C standard, each implementation has the discretion to determine how to represent type names.

In the case of GCC, the name returned by typeid.name() carries additional information known as a "mangled name." This format includes decorations that serve internal compiler purposes. To obtain the unmangled type name, you can employ the c filt command or the __cxa_demangle function.

c filt 4Blah

Output: struct Blah

__cxa_demangle("4Blah", nullptr, nullptr, nullptr)

Output: Blah

By utilizing these tools, you can demangle the decorated type names and retrieve the desired unmangled representation.

The above is the detailed content of How Can I Demangle GCC\'s Mangled Type Names from typeid.name()?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn