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 are the advantages of c++ over c?

840


Show the declaration for a pointer to function returning long and taking an integer parameter.

830


What is the meaning of c++?

813


What is new in c++?

901


What are the advantages of using typedef in a program?

893


How to implement is-a and has-a class relationships?

808


How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Why is it difficult to store linked list in an array?how can you find the nodes with repetetive data in a linked list?

1068


What is the benefit of learning c++?

753


Is there any function that can skip certain number of characters present in the input stream?

820


What is object in c++ example?

881


What is private public protected in c++?

778


What is the advantage of c++ over c?

788


How can you quickly find the number of elements stored in a static array?

875


What can I safely assume about the initial values of variables which are not explicitly initialized?

851


What are the differences between new and malloc?

842