#include <dynam.h>; void loadm(const char *name, __remote /* type */ (**fpp)());
loadm
loads an executable module named by the argument string
name
and stores a C function pointer
in the location pointed to by the argument
fpp
. If the module has been loaded already, the pointer stored in
fpp
points to the previously loaded
copy. If the module name in the first argument string is prefixed with an
asterisk, a private copy of the module is loaded. Note that
fpp
may reference a function returning any valid
type of data.
loadm
provides an indirect return value in the form of a function pointer
that addresses the entry point of the loaded module. If the module is in
C, calling the returned function always transfers control to the
_dynamn
function of the module.
If the module to be loaded cannot be found, a
NULL
is stored in the location
addressed by
fpp
.
Various user ABENDs, notably 1217 and 1218, may occur if overlays of library storage are detected while dynamic loading is in progress.
The first argument string may be no more than eight characters long, not counting a leading asterisk.m
is not portable. Be aware of system dependencies involving where
load modules may be located and how module names are specified for your operating
system.
The implementation of
loadm
necessarily varies from operating system
to operating system. Under OS/390, modules to be loaded must reside in STEPLIB,
a task library, or the system link list. Under CMS, modules to be loaded
may reside in DYNAMC LOADLIB or in other locations defined by use of the
addsrch
routine. Under CICS, modules
to be loaded must reside in a library in the DFHRPL concatenation and must
be defined to CICS.
addsrch
does not verify the existence of a location, for example, DYNAMC
LOADLIB. Because in some circumstances the logic of a program may not require
that a location be searched, no verification is done until
loadm
cannot find a load module in any location
defined earlier in the search order.
addsrch
fails only if its parameters are ill-formed.
If
loadm
determines that a location is inaccessible (for example, the LOADLIB
does not exist), the location is marked unusable, and no attempt is made to
search it again.
The use of
loadm
is illustrated by three examples. The first demonstrates the
use of the command for a very simple situation without operating-system dependencies,
while second and third examples are designed to run under OS/390 and CMS respectively.
The second example creates a dynamic load module that includes a table of pointers to functions which may be called dynamically from the calling load module. This example runs under OS/390); . . .
Example 1.2 illustrates techniques for managing load modules containing multiple functions. This example includes illustrative OS/390 JCL, but the techniques illustrated in the example are also applicable to CMS.
compiler option to override the default
assignment of
_dynamn
as
the section name. It may be compiled as re-entrant using the
rent
compiler option. (Note that JCL changes
are required if
norent
compilation //
A C source file, NEPTUNE C (listed below), is to be dynamically loaded and
executed. The file contains the function
neptune
.
#include <stdio.h> void neptune(char *p) { puts(p); return; }
STEP I. Make the function
neptune
into for more information about the
snamecompiler option.
LKED NEPTUNE (LIBE DYNAMC NAME NEPTUNE
The LKED command creates the file DYNAMC LOADLIB, containing the member NEPTUNE (assuming the LOADLIB did not already exist).
is required. If you use some other filename for the LOADLIB,
specify it in a call to
addsrch
before.
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.