Interfacing - The Issues [ Micro Focus COBOL for UNIX COBOL User Guide ] MPE/iX 5.0 Documentation
Micro Focus COBOL for UNIX COBOL User Guide
Interfacing - The Issues
This section considers some of the basic issues involved in interfacing
so that you can get a better understanding of how and when to use the
special COBOL syntax for overcoming these problems. It also describes
the additional syntax available for dealing with the different calling
conventions.
Calling Interface Compatibility
In the UNIX environment the COBOL system conforms exactly to the C
conventions, so there are few compatibility issues. However, if you
intend to make your programs portable to non-UNIX environments, you
should be aware of the issues.
In order for a call to work it is important that both calling program and
called subprogram obey the same rules. The most important of these rules
govern the following:
* The order the parameters are pushed onto the stack by the calling
program
* When the parameters are removed from the stack
* The format of the parameters
* How any return code is returned to the calling program
* Which registers are preserved by a subprogram
If the calling program and the called subprogram do not obey the same
protocol then the application is liable to crash when the call is made.
Parameter Ordering.
Parameters are always passed by pushing the parameters onto the stack
before calling the subprogram. The parameters can be pushed onto the
stack by either processing the list of call parameters from right-to-left
(reverse order) or from left-to-right (order specified).
Parameter Removal.
There are two choices as to when the parameters are removed from the
stack. They can be removed by the called subprogram before it terminates
and returns to the calling program, or by the calling program immediately
after it receives control back.
Parameter Format.
COBOL supports two methods of passing parameters to a subprogram in a
mixed-language environment:
by reference Passes an address. Any changes made to the
parameter by the subprogram are reflected in the
calling program.
by value Passes only the value of the parameter to the
subprogram. Any changes made to the parameter in
the subprogram are not reflected in the calling
program.
Program Return Code.
Most languages are capable of passing a return code back to the calling
program.
MPE/iX 5.0 Documentation