Converts all references to an identifier to another, externally defined identifier.
#pragma map syntax – C >>-#--pragma--map--(--name1--,--"--name2--"--)-----------------><
#pragma map syntax – C++ >>-#--pragma--map--(--name1--(--argument_list--)--,--"--name2--"--)-><
name1 should be declared in the same compilation unit in which it is referenced, but should not be defined in any other compilation unit. name1 must not be used in another #pragma map directive or any assembly label declaration anywhere in the program.
name2 can represent a data object, a non-overloaded or overloaded function, or overloaded operator, with external linkage. name2 must be specified using its mangled name. To obtain C++ mangled names, compile your source to object files only, using the -c compiler option, and use the nm operating system command on the resulting object file. You can also use can the c++filt utility provided by the compiler for a side-by-side listing of source names and mangled names; see Demangling compiled C++ names for details. (See also Name mangling for details on using the extern "C" linkage specifier on declarations to prevent name mangling.)
If the name exceeds 65535 bytes, an informational message is emitted and the pragma is ignored.
name2 may or may not be declared in the same compilation unit in which name1 is referenced, but must not be defined in the same compilation unit. Also, name2 should not be referenced anywhere in the compilation unit where name1 is referenced. name2 must not be the same as that used in another #pragma map directive or any assembly label declaration in the same compilation unit.
The #pragma map directive can appear anywhere in the program. Note that in order for a function to be actually mapped, the map target function (name2) must have a definition available at link time (from another compilation unit), and the map source function (name1) must be called in your program.
You cannot use #pragma map with compiler built-in functions.
/* Compilation unit 1: */ #include <stdio.h> void foo(); extern void bar(); /* optional */ #if __cplusplus #pragma map (foo, "bar__Fv") #else#pragma map (foo, "bar") #endif int main() { foo(); } /* Compilation unit 2: */ #include <stdio.h> void bar() { printf("Hello from foo bar!\n"); }The call to foo in compilation unit 1 resolves to a call to bar:
Hello from foo bar!
// Compilation unit 1: #include <iostream> #include <string> using namespace std; void foo(); void foo(const string&); extern "C" void bar(const string&); // optional #pragma map (foo(const string&), "bar") int main() { foo("Have a nice day!"); } // Compilation unit 2: #include <iostream> #include <string> using namespace std; extern "C" void bar(const string& s) { cout << "Hello from foo bar!" << endl; cout << s << endl; }The call to foo(const string&) in compilation unit 1 resolves to a call to bar(const string&):
Hello from foo bar! Have a nice day!