Question

I came across this article on dynamic linking in C++.

We can create a C++ factory which would return an object of the class we are interested. Also, we should create a static object in file scope for the factory so that it can be located using dlsym(). (The article suggests that static objects are not name mangled.)

Why are static objects not name mangled?

Was it helpful?

Solution

Name mangling is invented to assist in resolving overloaded function names. You can define several functions with the same name, differing only in the count and the types of their parameters. Name mangling lets the linker resolve such functions to the correct place in the code.

Unlike names of functions, names of static objects in the global namespace cannot be overloaded, so mangling them is not necessary. Names of objects that are outside of global namespace are, in fact, mangled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top