What is Name Mangling in C++ ?

"The process in which C++ compiler assigns a unique name to the functions (or other entities) is known as Name Mangling."



  • C++ support function overloading (i.e. many functions with the same name and different number of arguments), so in order to uniquely identify each function, C++ complier changes its name by adding some more information about the arguments.
For example :
int fun(){
return 0;
}
int fun(int i){
return i;
}
Here, C++ compiler may mangled them as :
int __fun_v(){
return 0;
}
int __fun_i(int){
return i;
}

  • Name mangling also applies to the variable names, so that variable with the same name can exist in different namespaces.
  • Name mangling is compiler dependent, i.e., there is no standard for assigning a unique name to the function, different compilers use different techniques for name mangling.