Table of Contents

C++ Name mangling

Name mangling is how C++ compilers encode function and variable names to support overloading and namespaces. The mangled symbol encodes the namespace, class, function name, and parameter types—e.g., Hello::World::add<int>(int, int) becomes _ZN5Hello5World3addIiEET_S2_S2_ following the Itanium ABI.

Mangling rules follow the Itanium C++ ABI standard. You can demangle names with c++filt to see the original signature.

Example

This example shows how template instantiations generate distinct mangled symbols.

// compile: g++ -o mangling mangling.cpp
// run: ./mangling
// description: template instantiations produce distinct mangled symbols
 
namespace Math {
    template <typename T>
    T add(T x, T y) {
        return x + y;
    }
}
 
int main() {
    int i = Math::add(1, 2);
    double d = Math::add(1.5, 2.5);
    return 0;
}