Calling C Programs via the Interface Method

The interface method uses special routines that are passed the name of the called function. Use this method when you want to simulate the actions of a non-native system. ACUCOBOL-GT supports two types of interfaces that simulate interfaces available in two versions of RM/COBOL:

You may use either or both of these interfaces. With the interface method, parameters are passed to the interface routines in a standardized format. The parameters must typically be converted to a format that is usable in C.

Every ACUCOBOL-GT compiler comes with a sample C subroutine interface. The "sub.c" file implements the "sub" interface. The "sub85.c" file implements the "sub85" interface. The "sub.h" file contains some useful definitions, particularly if you are using the "sub85" interface. These files contain extensive comments describing how they are used. They also contain the source to the SYSTEM library routine. You can use these files as the starting point for your code. The two interfaces are described in the following sections.

Note: At run time, the "sub" interface performs a linear search for a called routine. This process can be inefficient when a very large number of "sub" routines are present. If your program calls a large number of C routines, we recommend that you use the "sub85" or "direct" interface.

Also, in the "sub85" and "sub" interface methods, parameters are not passed directly to the C routine. Instead, an array of pointers is passed, and each pointer points to the corresponding parameter (or in the case of "sub85," a description of the parameter). In this case, the notion of BY VALUE has no reasonable definition, because there is no place to put the value. Because of this, the runtime ignores the BY VALUE phrase and passes an address to a copy of the value (essentially treating BY VALUE as BY CONTENT). It must do this because there is no C variable available in which to pass the value. However, specifying NULL does have a reasonable definition: The pointer corresponding to that parameter is set to binary zeros. Therefore, with the interface method, NULL and BY VALUE ZERO have different meanings (contrast this with the corresponding note under the direct method described in the topic Calling C Programs via the Direct Method).