Supported data types passed by value (indirect) or by reference (indirect) between C++ and COBOL

Table 1 identifies the data types that can be passed by value (indirect) or by reference (indirect) between C++ and COBOL applications.

Table 1. Supported data types passed by value (indirect) or by reference (indirect) with extern "C"
C++ (Pointer to...) COBOL (by content/by reference)
char PIC X, PIC A
signed short int PIC S9(4) USAGE IS BINARY
unsigned short int PIC 9(4) USAGE IS BINARY
signed int, signed log int PIC S9(9) USAGE IS BINARY
unsigned int PIC 9(9) USAGE IS BINARY, LENGTH OF
unsigned long int PIC 9(9) USAGE IS BINARY
float COMP-1
double COMP-2
pointer to... POINTER, ADDRESS OF
struct Groups
type array[n] Tables (OCCURS n TIMES)
Note:
  1. You must specify a size for type array.
  2. If the COBOL program receives int parameters from the C calling function that might have a value that is larger than that declared as the maximum size by the COBOL picture clause, the COBOL program must either be compiled with the TRUNC(BIN) compiler option or each binary data item that receives int parameters from C must be declared as USAGE IS COMP-5. Taking these actions will guarantee that truncation of high-order digits does not occur. For more information about the TRUNC(BIN) compiler option or about using COMP-5 data items, see the appropriate version of the programming guide in the Enterprise COBOL for z/OS library.
  3. COBOL always turns on the high-order bit of the address of the last parameter. This can cause problems in the C++ program if it is using the address (since it will be treated as a negative number). If a C++ program does need to use the address of the last parameter, one of the following techniques can be used to bypass this problem:
    • If the COBOL program is an Enterprise COBOL program, instead of passing the parameter by reference, pass the address of the item by value. For example, use a call statement that looks like this:
      CALL "C" using by value address of C-PARM1
      	             by value address of C-PARM2
    • If the COBOL program is not Enterprise COBOL, code must be added to mask out the high-order bit in the C++ routine. The sample code shows how to do this:
          #include <stdio.h>
          #include <string.h>
          void A1CC01B1(char* myString)
          {
            myString = (char*)((int)myString & 0x7fffffff);
            printf("My String: %s \n", myString);
            return;
          }