The process for specifying the linkage to assembler differs for
C and for
C++. In C, a #pragma linkage directive is used, while
in
C++ a linkage specifier is used.
- Under C, a #pragma linkage directive enables the compiler
to generate and accept parameter lists, using a linkage convention
known as OS linkage. Although functionally different, both calling an assembler routine and being
called by one are handled by the same #pragma. Its
format is shown below, where identifier is the name of the
assembler function to be called from C or the C function to be called
from assembler. The #pragma linkage directive must occur
before the call to the entry point.
#pragma linkage(identifier, OS)
- Under C++, a linkage specifier enables the compiler to generate
and accept parameter lists, using a linkage convention known as OS
linkage. Although functionally different, both calling an
assembler routine and being called by one
are handled by the same linkage specifier. The format of the linkage
specifier is shown below, where fnx desc is the name of the
OS entry point:
extern "OS" {
fn1 desc;
fn2 desc;
⋮
}
Note: For C and C++, in XPLINK compiled code, the OS_UPSTACK and OS_NOSTACK (or OS31_NOSTACK)
linkages are used for declaring the linkage convention of a routine
that the C or C++ code is calling. You cannot
define C or C++ entry points as having OS_NOSTACK linkage.
You define C or C++ entry points with OS_UPSTACK linkage
by compiling the translation units containing them with the NOXPLINK
compiler option. In NOXPLINK compiled code, the OS_DOWNSTACK linkage
is used to declare the linkage convention for a routine that the C
or C++ code is calling. You define C or C++
entry points with OS_DOWNSTACK linkage by compiling the
translation units containing them with the XPLINK compiler option.
Just as C (or C++) linkage programs can call OS linkage programs,
OS linkage programs can call C linkage programs. An example of C
linkage calling OS linkage, which in turn calls C linkage (in this
case, one of the z/OS® XL C/C++ library functions) is shown in Figure 1.
In general, any type that can be passed between C and assembler
can also be passed between C++ and assembler. However, if a C++ class
that uses features not available to assembler (such as virtual functions,
virtual base classes, private and protected data, or static data members)
is passed to assembler, the results will be undefined.
Note: In C++, a structure is just a class declared with
the keyword struct. Its members and base classes are public
by default. A union is a class declared with the keyword union its
members are public by default, and it holds only one member at a time.