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

What is the difference between ++ count and count ++?

801


What are the types of pointer?

764


List the merits and demerits of declaring a nested class in C++?

775


Explain one-definition rule (odr).

845


Why c++ is better than c language?

772


When do we run a shell in the unix system?

788


Can we define function inside main in c++?

752


What is the difference between an enumeration and a set of pre-processor # defines?

1056


Describe new operator?

834


What is expression parser in c++

2123


What are the different types of polymorphism in c++?

807


Explain public, protected, private in c++?

733


What is the use of lambda in c++?

748


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

789


What parameter does the constructor to an ofstream object take?

809