Passing data by reference (indirect) between C and COBOL

A parameter can be passed by reference (indirect) between C and COBOL, which means 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 as COBOL parameters. Conversely, to pass data by reference (indirect) from COBOL to C, the variables are passed from COBOL as BY REFERENCE arguments and received by a C function as pointers to a given type. For example, if a C function called FROMCOB is to receive a parameter passed by reference (indirect) of type int, the function prototype declaration would look like this:
void FROMCOB(int *)

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. Therefore, 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).