K
Karl Heinz Buchegger
Randy said:Why is this necessary? The identifiers provide by the
programmer are unique, and that is what is important - why
map what the user has specified to something else?
Because most C++ compilers are built around a system dependent
linker. Those linker have a simple rule: if 2 functions have
the same name, then they are the same function. This was
true in most (if not all) programming languages which
required linking.
But in C++ it is perfectly valid to have 2 different functions
with the same name, if only their argument types are different.
That's why name mangling was introduced: To add information to
the name of a function to create different names for functions
with the same name but different argument types.
The alternative would have been to write new a new object file
format and a new linker that can deal with that. As long as you
only have C++ this would be no big problem. But as said: on most
'big machines' (such as mainframes), there is only one object
file format defined and only one system wide linker to link
an application. That's a good thing, because it means you can
freely link modules written in different programming languages.
But it also means: You have to introduce some mechanism for
the compiler to make function names unique even if they have identical
names in the source code.