When you build from C++ sources, VisualAge C++ encodes all C++ function names and certain other identifiers to create an internal representation that includes type and scoping information. This encoding process is called mangling. The linker uses mangled names to ensure type-safe linkage. The mangled names are used in object files, and executable files, and libraries. Tools that use these files must use the mangled names and not the original names used in the source code.
You can use any of the following features of VisualAge C++ to convert mangled C++ names to the demangled form which is how the name appears in source code:
- Demangling functions in the runtime library.
The c++filt command
The cppfilt command
Using the Demangling Functions
The VisualAge C++ runtime library contains a small class hierarchy of functions that you
can use to demangle names. The demangling functions are available in both the static and
dynamic versions of the library. The interface is documented in the <demangle.h>
header file.
You can call these functions to convert a mangled name to a demangled name and to determine characteristics of that name, such as its type qualifiers or scope. For example, given the mangled name of a function, you can write a program to find the demangled name of the function and the name of its qualifiers. If the mangled name refers to a class member, you can determine if it is static, const, or volatile. You can also get a demangled string containing the qualified function name with its parameter types.
To demangle a name, create a dynamic instance of the Name class and provide the mangled name as a character string to the constructor. For example, the following two lines are taken from a program that demangles the name f__1XFi:
char *rest;
Name *name = Demangle("f__1XFi", rest);
The Demangle function returns a name in the form required for the demangling functions. It takes two paramters:
The demangling functions classify names into categories:
After you construct an instance of class Name, you can use the Kind member function of Name class to determine what kind of Name the instance is. Based on the kind of name returned, you can ask for the text of the different parts of the name or of the entire name.
For example, here are some function calls and the information returned in a program that demangles f__1XFi.
| Function Call | Returned Information |
|---|---|
| name->Kind() | MemberFunction |
| ((MemberFunctionName *) name)->Scope()->Text() | "X" |
| ((MemberFunctionName *) name)->RootName() | "f" |
| ((MemberFunctionName *) name)->Text() | "X::f(int)" |
If the character string passed to the Demangle function is not a mangled name, the demangle function returns NULL.
The run-time library also provides a C-language interface you can use in C programs. The functions use no external C++ features.
![]()
Get Mangled Names for C++ Symbols
