skip to main content

Calling C Language Functions and Other External Routines : Program Examples

Program Examples
The following example programs show how a C language routine can be called from isCOBOL:
The C source file “calltest.c” has these lines:
#include <stdio.h>
calltestc(int *pitem1)
      printf("item1 = %x\n", *pitem1);
Compile this routine using the C compiler, then link it into a shared object library called “calltestc.so”.
The programmer can access this shared object library from COBOL in one of two ways:
-or-
The isCOBOL program called, “calltest.cbl” has the following lines (Notice how the data variable item-1 is declared with storage to complement the C language routine it will be calling.):
       id division.
       program-id. calltest.
       data division.
       working-storage section.
       77 item-1 pic 9(8comp-5.
       procedure division.
            move x#7fff to item-1.
            display item-1.
      * comment – delete the following line if using the
      *  iscobol.shared_library_list method:
       call "calltestc.so".
       call "calltestc" using item-1.
More examples can be found in the $ISCOBOL_HOME/sample/is-c folder installed with isCOBOL

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left