#pragma map

Category

Object code control

Purpose

Converts all references to an identifier to another, externally defined identifier.

Syntax

Read syntax diagramSkip visual syntax diagram
#pragma map syntax – C

>>-#--pragma--map--(--name1--,--"--name2--"--)-----------------><

Read syntax diagramSkip visual syntax diagram
#pragma map syntax – C++

>>-#--pragma--map--(--name1--(--argument_list--)--,--"--name2--"--)-><

Parameters

name1
The name used in the source code. C only name1 can represent a data object or function with external linkage. C++ only name1 can represent a data object, a non-overloaded or overloaded function, or overloaded operator, with external linkage. If the name to be mapped is not in the global namespace, it must be fully qualified.

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.

C++ only argument_list
The list of arguments for the overloaded function or operator function designated by name1. If name1 designates an overloaded function, the function must be parenthesized and must include its argument list if it exists. If name1 designates a non-overloaded function, only name1 is required, and the parentheses and argument list are optional.
name2
The name that will appear in the object code. C only name2 can represent a data object or function with external linkage.

C++ only 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.

Usage

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.

Examples

The following is an example of #pragma map used to map a function name (using the mangled name for the map name in C++):
/* 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!
C++ only The following is an example of #pragma map used to map an overloaded function name (using C linkage, to avoid using the mangled name for the map name):
// 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!

Related information