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 best c++ book?

703


What are static and dynamic type checking?

602


Which is the best c++ software?

598


Write about the local class and mention its use?

599


What are the restrictions apply to constructors and destructors?

633






What is the use of lambda in c++?

564


To which numbering system can the binary number 1101100100111100 be easily converted to?

597


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

600


Write about c++ storage classes?

738


How do I run c++?

566


what are the decision making statements in C++? Explain if statement with an example?

648


describe private access specifiers?

626


What is set in c++?

651


Why is standard template library used?

569


How would you implement a substr() function that extracts a sub string from a given string?

556