Previous Topic Next topic Print topic


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 %ProgramFiles(x86)%\Micro Focus\Enterprise Developer\include (Windows) or $COBDIR/include (UNIX) by default.

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 located in %ProgramFiles(x86)%\Micro Focus\Enterprise Developer\include (Windows) or $COBDIR/include (UNIX) by default.

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 C Functions for Calling COBOL section.

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 a process calls fork(), without a corresponding exec(), then the child should call cobinit() before using any COBOL functionality. In such cases, the parent should not call COBOL, either before or after calling fork(), and should only have one thread at the time that fork() is called.

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

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.

Previous Topic Next topic Print topic