Mangled names always start with _Z
. Following this is
the mangled name of either a function and its type, an object
name, or a "special name".
There are a number of attributes that will be included in the mangled name of a function:
Within the mangling there are a lot of types. Some have a short name, others get their full name.
Type | Mangled Representation |
---|---|
void | v |
int | i |
std::string | Ss |
std::ostream | So |
int Something::Inside::Deeper::deeperMethod(void) | _ZN9Something6Inside6Deeper10deepMethodEv |
int Something::Inside::Deeper:: deeperMethod(std::vector<std::string>) | __ZN9Something6Inside6Deeper10deepMethod ENSt3__16vectorINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS7_IS9_EEEE |
For more detail, you can do worse than Wikipedia: Name Mangling in C++
When you want to link with a C method, or be able to have a method called from C, you need to tag it as extern C. This tells the compiler not to mangle the symbol, so it will have a basic C looking symbol. For global variables there is no mangling and extern is redundant. But variables declared without extern are implicitly static. If they are initialized they will need symbols, and those symbols are mangled to avoid conflicting in the linker.