Passing data by reference (indirect) between C++ and COBOL

A parameter can be passed by reference (indirect) between C++ and COBOL. By reference (indirect) means that the actual address of the argument is passed to the called function or procedure; any changes to the parameter made by the called routine can alter the original parameter passed by the calling routine.

To pass data by reference (indirect) from C++ to COBOL, the variables are passed by C++ as function arguments, which are pointers to a given type or the address of a given variable, and received by COBOL as BY REFERENCE parameters. Conversely, to pass data by reference (indirect) from COBOL to C++, the variables are passed by COBOL as BY REFERENCE arguments and received by C++ function as pointers to a given type.

The C++ function must dereference the pointer to access the actual value. If the value of the pointer is modified by the C++ function, as opposed to modifying the value that the pointer points to, the results on return to COBOL are unpredictable. Thus, passing values by reference (indirect) from COBOL to C++ should be used with caution, and only in cases where the exact behavior of the C++ function is known.

Table 1 shows the supported data types for passing by reference (indirect).