PROTECT-LINKAGE

Note:

This directive is not supported under UNIX.

Normally, the result of ignoring the constraints would give undefined results, possibly including severe errors such as protection violations or memory access faults.

Syntax:

>>-.---.-.----.--PROTECT-LINKAGE-----------><
   +-/-+ +-NO-+

Parameters:

None

Properties:

Default: NOPROTECT-LINKAGE (Dialect)
Phase: Syntax check
$SET: Initial

Comments:

The ANSI COBOL standard states in the general rules for each parameter passed by the CALL statement that "The description of the data item in the called program must describe the same number of character positions as described by the description of the corresponding data item in the calling program.". This restriction must be observed when using this COBOL system unless the program is compiled with the PROTECT-LINKAGE directive.

The restriction is lifted when the PROTECT-LINKAGE directive is set. The called program only uses mismatched parameters as sending items in a statement and does not use them as receiving items.

Any character positions in a parameter for which there is no correspondence in the called and calling programs is a mismatched character. The contents of any mismatched character is undefined for a parameter used as a sending item in a called program.

Don’t set PROTECT-LINKAGE and use CBL_ALLOC_MEM to allocate memory for linkage items at the same time.

Note:

This directive can adversely affect the performance of generated code.

Example:

Calling program:

     ...
     03 x1  pic x.
     03 x2  pic x(100).
 procedure division.
      ...
     call subprog using x1
      ...

Subprogram:

 working-storage section.
 01  y1       pic x(1000).

 linkage section.
 01  z1       pic x(1000).

 procedure division using z1.

     move z1 to y1
* This operation works, and transfers the contents of x1. It
* also transfers any data following x1 in the calling program,
* up to 1000 bytes or the end of allocated memory, whichever
* occurs first. If less than 1000 bytes is transferred, the
* remainder of y1 is space filled.

     move y1 to z1.
* This operation is not protected and fails, either by
* corrupting data beyond x1 in the calling program, or
* trying to write beyond allocated memory, which might
* result in a protection violation.