Hi Everyone,
I read somwhere that c++ compiler does name mangling of functions
which is why c source code can't invoke functions from object files
that were generated using c++ compiler. Can anyone tell in detail as to
what name mangling is all about?
In C, functions all exist in the global namespace. You can have only
one function with a particular name throughout your entire program. In
C++, you may have indefinitely many functions with the same name, so
long as each is in a different namespace, class, etc, or even in the
same namespace if they differ in the number or type of arguments.
Clearly, its name alone is no longer sufficient for a linker to uniquely
identify a function, so some C++ compilers solve this problem by giving
functions that have the same name in the source code some mangled name
in the object file. This mangled name might take into account the
class, namespace, and number and type of arguments the function has so
that each function with the same name will have a different mangled name.
Note, however, that how this is done (or whether it is done at all) is
an implementation detail. The standard doesn't say anything about name
mangling.