Description
The #pragma linkage directive identifies the linkage or calling convention used on a function call. Linkage keywords are easier to use than the #pragma linkage directive, and they let you declare both the function and its linkage type in one statement.
Syntax
The identifier identifies either the name of the function that will be given the particular linkage type or the name of a typedef that resolves to a function type. If identifier is a typedef, any function declared using identifier will be given the particular linkage type.
The following example shows how to use a typedef to declare functions and pointers to functions of _System linkage:
#pragma linkage(functype, system) typedef int functype(int); functype f; /* f is a function with _System linkage */ functype *fp; /* fp is a pointer to a function with _System linkage */
The VisualAge C++ default calling convention is _Optlink, which is a convention specific to the VisualAge C++ product.
If your program calls OS/2 APIs, you must use the
_System calling convention, which is standard for all OS/2
applications to call those APIs. If you include the system header
files, the OS/2 APIs are automatically given _System linkage.
If you are developing device drivers, you should use
the _Pascal convention. You should use the _Far32 version of
_Pascal linkage if your calls will cross code segments. Note that
_Far32 _Pascal linkage is only available when you specify the gen(ring0,
...) option to generate code that runs
at ring zero.
The _Far16 linkage conventions indicate that a
function has a 16-bit linkage type.
The cdecl and _ cdecl options are equivalent. The underscore is optional, and is accepted for compatibility with C/2 cdecl linkage declarations.
Similarly , pascal and _pascal are equivalent, and
specify C/2 pascal linkage; fastcall and _fastcall specify
Microsoft** _fastcall linkage. If far16 is specified without a
parameter, __cdecl linkage is used.
You can use compiler options to explicitly set the calling convention:
| Linkage | Option |
|---|---|
| _Optlink | gen(call, optlink) |
| _System | gen(call, system) |
| __cdecl | gen(call, cdecl) |
| __stdcall | gen(call, stdcall) |
A linkage keyword or #pragma linkage directive overrides the compiler option.
![]()
Preprocessor
Directives - An Overview
Preprocessor
Directive - #pragma
![]()
ring0 Code
Generation Option - gen(ring0, ...)
![]()
call Code
Generation Option - gen(call, ...)
