You can set procedure-pointer
and function-pointer data items only by using format 6 of the
SET statement.
Procedure pointers are data items defined with the
USAGE IS PROCEDURE-POINTER clause.
Function pointers are data items defined with the
USAGE IS FUNCTION-POINTER clause.
In this information, "pointer" refers to either a procedure-pointer
data item or a function-pointer data item.
You can set either of these data items
to contain entry addresses of, or pointers to, these entry points:
- Another COBOL program that is not nested.
For example, to have
a user-written error-handling routine take control when an
exception condition occurs, you must first pass the entry address
of the routine to CEEHDLR, a condition-management
Language Environment callable
service, so that the routine is registered.
- A program written in another language.
For example, to receive
the entry address of a C function, call the function with the
CALL RETURNING statement.
It will return a pointer that
you can either use as a function pointer or convert to a procedure
pointer by using a form of the SET statement.
- An alternate entry point in another COBOL program (as defined
in an ENTRY statement).
The SET statement sets the pointer to refer either to an entry
point in the same load module as your program, to a separate load
module, or to an entry point that is exported from a DLL, depending
on the DYNAM|NODYNAM and DLL|NODLL
compiler options.
Therefore, consider these
factors when using these pointer data items:
- If you compile a program with the NODYNAM and
NODLL options and set a pointer item to a literal value
(to an actual name of an entry point), the value must refer to an
entry point in the same load module. Otherwise the reference cannot
be resolved.
- If you compile a program with the NODLL option
and either set a pointer item to an
identifier that will contain the name of the entry point at run
time or set the pointer item to a literal and compile with the
DYNAM option, then the pointer item, whether a literal or
variable, must point to an entry point in a separate load module.
The entry point can be either the primary entry point or an
alternate entry point named in an ALIAS linkage-editor
or binder statement.
- If you compile with the NODYNAM and DLL
options and set a pointer item to a literal value (the
actual name of an entry point), the value must refer to an entry
point in the same load module or to an entry-point name that is
exported from a DLL module.
In the latter case you must include the
DLL side file for the target DLL module in the link edit of your
program load module.
- If you compile with the NODYNAM and DLL
options and set a pointer item to an identifier (a
data item that contains the entry point name at run time), the
identifier value must refer to the entry-point name that is
exported from a DLL module.
In this case the DLL module name must match the name of the exported entry point.
If you set a pointer item to an entry address in a dynamically
called load module, and your program subsequently cancels that
dynamically called module, then that pointer item becomes
undefined.
Reference to it thereafter is not reliable.