Interfacing with C Programs

This COBOL system provides a number of library functions that enable you to mix C and COBOL programs. These functions are intended primarily for use in C programs.

The functions are prototyped in C header files, which are located in the $COBDIR/include directory.

The functions use portable data types, which have the naming convention cobtype_t. Definitions of these data types can be found in the cobtypes.h header file in the $COBDIR/include directory.

A C function can call a COBOL entry point in the same way as it would call another C function.  For example, the following demonstrates C code that calls a COBOL entry point, cobep, using two arguments:

cobep(arg1, arg2);

A C function can call, and cancel, COBOL programs and entry points using the cobcall(), cobcancel() and cobfunc() routines, as described in the sections below.

Before calling a COBOL program, you must call cobinit(). In a threaded environment where you don't know if you're the first thread or not, each thread should call cobinit().

If your application has a C main() and the command line needs to be accessed from COBOL, then you must call cobcommandline().

Before exiting a thread that has called a COBOL program, but which was not created via COBOL multi-threading syntax or library routines, you must call cobthreadtidy().

Before exiting an application that has called a COBOL program you must call either cobtidy() or cobexit().

If the COBOL program and the C function that calls it are not contained in a callable DLL/shared object, nor linked together in a system executable file, then:

All the C routines for calling COBOL are described in reference topics.