Consider the following example.
namespace Gandalf{ namespace Frodo{ bool static hasMyPrecious(){ // _ZN7Gandalf5FrodoL13hasMyPreciousEv return true; } }; bool static hasMyPrecious(){ // _ZN7GandalfL13hasMyPreciousEv return true; } }; namespace Sauron{ bool static hasMyPrecious(){ // _ZN5SauronL13hasMyPreciousEv return true; } }; bool hasMyPrecious(){ // _Z13hasMyPreciousv return true; } int main() { if( Gandalf::Frodo::hasMyPrecious() || // _ZN7Gandalf5FrodoL13hasMyPreciousEv Gandalf::hasMyPrecious() || // _ZN7GandalfL13hasMyPreciousEv Sauron::hasMyPrecious() || // _ZN5SauronL13hasMyPreciousEv hasMyPrecious()) // _Z13hasMyPreciousv return 0; return 1; }
In accordance with the namespace in which the function is declared, the compiler generates a unique name for each Mangled Name function, which is nothing but the encoding of the namespace area in which the function is defined, the function name, return type, and actual parameters. see comments. When you create calls for these functions, each function call searches for the same chained signature if no compiler error is found.
Try experimenting with clang -emit-llvm -S -c main.cpp -o main.ll if you are interested in working internally.
Mahesh attarde
source share