z/OS Language Environment Writing Interlanguage Communication Applications
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Calling between C++ and COBOL

z/OS Language Environment Writing Interlanguage Communication Applications
SA38-0684-00

The following tables describe the types of calls that are supported between C++ and COBOL when running with Language Environment®.
  • Table 1 shows which calls are supported from COBOL programs to C++ routines.
  • Table 2 shows which calls are supported from C++ routines to COBOL programs.
Within a given enclave containing ILC between COBOL and C++, the application may be structured in one of the following ways:
  • As a single statically-bound load module.
  • As a DLL application, with multiple DLL load modules, each containing DLL-enabled COBOL and C++ routines.
  • As an application using multiple load modules and using COBOL dynamic CALLs. In this case, all instances of C++ ILC must be statically-bound within the main load module. The only exception would be if extern "COBOL" or extern "C" is specified for all C++ functions called by COBOL that are in dynamically called load modules that do not contain any DLL routines that export functions or variables.
  • As an application using multiple load modules and using fetch.
Table 1. Support for calls from COBOL to C++
Caller Call type Target
C++ with extern "COBOL" C++ with extern "C" C++ without extern
VS COBOL II (1) static Yes with restrictions (2) No No
COBOL/370 (1) static Yes No No
COBOL (5) compiled with NODLL static Yes Yes No
VS COBOL II (1) dynamic No No No
COBOL/370 (1) dynamic No No No
COBOL (5) compiled with NODLL dynamic Yes (3) Yes (3) No
COBOL (6) compiled with DLL CALL "literal" to a function within the module Yes Yes No
COBOL (6) compiled with DLL CALL "literal" to a function exported from a DLL Yes (4) Yes (4) No
COBOL (6) compiled with DLL CALL identifier to a function exported from a DLL Yes (4) Yes (4) No
Note:
  1. When the caller is VS COBOL II or COBOL/370, all calls must be to void functions.
  2. Static calls are supported from VS COBOL II to C++ with extern "COBOL" in the following cases:
    • The call is done in the main load module.
    • The call is done in a load module whose entry point is a Language Environment-conforming program or routine that was called using COBOL dynamic call.
    • The call is done in a module that was called using fetch.
    • The call is done in a DLL that was called using DLL linkage.
  3. Dynamically called load modules cannot contain any DLL routines that export functions or variables. Use the binder DYNAM(NO) control statement to prevent marking the load module as a DLL.

    The XL C/C++ compiler may mark certain internal symbols as exported, resulting in the C++ executable being a DLL. To prevent the XL C++ compiler from doing this, use the NOEXPORT(NOSYS) compiler option.

  4. In this case, the C++ code can also be compiled with the XPLINK option. The XPLINK C++ code must reside in a separate module from the COBOL caller.
  5. COBOL for MVS™ & VM, COBOL for OS/390® & VM, or Enterprise COBOL for z/OS
  6. COBOL for OS/390 & VM or Enterprise COBOL for z/OS
Table 2. Support for calls from C++ to COBOL
Caller Call type Target
VS COBOL II or COBOL/370 COBOL (4) compiled with NODLL COBOL (5) compiled with DLL
C++ with extern "COBOL" function is within the module Yes (1) Yes Yes
C++ with extern "C" function is within the module No Yes Yes
C++ without extern function is within the module No Yes No
C++ with extern "COBOL" fetch Yes (1, 2) Yes (2, 3) No
C++ with extern "C" fetch No Yes (2, 3) No
C++ without extern fetch No No No
C++ with extern "COBOL" function is exported from a DLL No No Yes (3)
C++ with extern "C" function is exported from a DLL No No Yes (3)
C++ without extern function is exported from a DLL No No No
Note:
  1. When the target of the call is VS COBOL II or COBOL/370, the called COBOL program must be declared as a void function.
  2. Fetched load modules cannot contain any DLL routines that export functions or variables.
  3. In this case, the C++ code can also be compiled with the XPLINK option. The XPLINK C++ code must reside in a separate module from the COBOL caller.
  4. COBOL for MVS & VM, COBOL for OS/390 & VM, or Enterprise COBOL for z/OS
  5. COBOL for OS/390 & VM or Enterprise COBOL for z/OS

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014