C++ › Compilation & Linking

What is name mangling?

Intermediate

Answer

Name mangling is how the C++ compiler encodes a function's name together with its namespace, class, and parameter types into a unique linker symbol—necessary because C++ supports overloading (same name, different parameters). It's why linker errors show decorated names and why calling C code needs extern "C" (which disables mangling for C-compatible names).
// void f(int) and void f(double) get different mangled symbols
Real-world example A link error shows a mangled symbol; demangling it reveals the exact overloaded function that's missing.

Common follow-ups: Why is mangling needed? | How does extern "C" relate to it?