Name mangling is the process by which the name of a function or variable in source code is translated to a symbol in an object file.

Name mangling becomes of primary importance when working on a mixed language project. This is because what might be callable as my_c_function() from C might become _my_c_function() or worse from another language.

In most languages/compilers, this process is fairly simple. In C, for instance, an underscore is prepended to the function name, with capitalization kept intact. Some other languages may change names to all uppercase, particularly if the language is case-insensitive.

In C++, however, because of the presence of classes and function overloading, it is necessary to be able to distinguish between multiple identical identifiers. This often involves a set of numbers and letters prepended to the function name, then an underscore is prepended to the name. Why the underscore? Because many of the original C++ compilers were essentially preprocessors to a C compiler. Therefore, if you wish to call some C++ code from C, you must declare the function extern "C".

Log in or register to write something here or to contact authors.