Calling COBOL Programs from C

Linking

  • Changes in the C compiler in Visual Studio 2015 affect the way you link COBOL object code and C object code built with that version of Visual Studio in the same executable. In this scenario, you must use the Microsoft link utility and the C runtime libraries directly from Visual Studio, rather than the Micro Focus cbllink utility, the Microsoft link utility and the libraries supplied with Visual COBOL. You might also need to specify some additional C runtime libraries - see the Microsoft documentation for more details.

    Note that when using COBOL and C object code together, Micro Focus recommends you build and keep the COBOL and C executables separate, and use import libraries and the Micro Focus C functions for calling COBOL (see "C functions for calling COBOL" in the product help) to resolve calls between them.

Calling a COBOL entry point directly

Note: The following instructions are required on little-endian PowerLinux platforms, but should also be considered good programming practice on other platforms. References to COBOL entry points in this topic include both the PROCEDURE DIVISION header and ENTRY statements.

When calling a COBOL entry point directly from C (as opposed to using cobcall() or cobfunc()), and passing fewer parameters than are specified on the entry point (that is, fewer actual parameters than formal parameters) then the COBOL entry point called from C should either:

  • Not be declared in the C program with a function prototype; or
  • Be declared in the C program with a function prototype with a variadic parameter list (see below).

Example

Take a COBOL program with the following entry points defined:

 entry "bob" using arg1 arg2 arg3 arg4 arg5 arg6
 arg7 arg8 arg9.

and a C program that contains code such as:

 i = bob(&x1, &x2);

then the correct way to declare this COBOL entry point in the C program is as follows:

 int bob(void *arg1, void *arg2,...);