What is name mangling?

Answer Posted / atul shankhwar

Name mangling is the process through which your c++ compilers give each function in your program a unique name. In C++, all programs have at-least a few functions with the same name. Name mangling is a concession to the fact that linker always insists on all function names being unique.

Example:
In general, member names are made unique by concatenating the name of the member with that of the class e.g. given the declaration:
class Bar
{
public:
int ival;
...
};
ival becomes something like:
// a possible member name mangling
ival__3Bar
Consider this derivation:
class Foo : public Bar
{
public:
int ival;
...
}
The internal representation of a Foo object is the concatenation of its base and derived class members.
// Pseudo C++ code
// Internal representation of Foo
class Foo
{
public:
int ival__3Bar;
int ival__3Foo;
...
};
Unambiguous access of either ival members is achieved through name mangling. Member functions, because they can be overloaded, require an extensive mangling to provide each with a unique name. Here the compiler generates the same name for the two overloaded instances(Their argument lists make their instances unique).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain virtual class?

701


What is the role of static keyword for a class member variable?

753


Perform addition, multiplication, subtraction of 2-D array using Operator Overloading.

3472


What is an adaptor class or wrapper class in c++?

734


Are there interfaces in c++?

687






Differences between private, protected and public and give examples.

692


What is the full form of stl in c++?

826


What is difference between c++ 11 and c++ 14?

692


What is the maximum combined length of command line arguments including the space between adjacent arguments?

699


Write about a nested class and mention its use?

750


what is a reference variable in C++?

802


Where and why do I have to put the "template" and "typename" keywords?

716


Is sorted c++?

744


Do you know about C++ 11 standard?

781


Why namespace is used in c++?

731