What is Name Mangling in C++ ?

Name Mangling is a process or technique performed by the C++ compiler to assign unique names to all the functions (or other entities).

C++ supports function overloading (i.e. many functions with the same name and different number of arguments), so in order to uniquely identify each function, C++ compiler 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;
}

Points to remember regarding Name Mangling:

  • 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.

Related Post

3 Replies to “What is Name Mangling in C++ ?”

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.