C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
7-30
Interfacing to TNS COBOL
*s = 'A';
arr[0] = 10;
MIGHT_LOSE_SEG (); /* Call TAL routine, which uses the*/
/* explicit extended data segment */
/* next two statements depend on the automatic extended */
/* data segment being restored after the call to TAL */
sarr[1] = *s;
arr[1] = arr[0] + 5;
}
Interfacing to TNS COBOL
Your TNS C/C++ programs can call functions written in TNS COBOL. The general
procedure consists of these steps:
Use the TNS COBOL compiler (COBOL85 in the Guardian environment or cobol
in the OSS environment) to compile the COBOL function.
Use the TNS C/C++ compiler (named c) to compile the C/C++ program.
Use Binder to link the two object files and create the executable.
Example 7-1 shows the contents of an example TNS C program, named TESTC, that
calls a COBOL function.
Example 7-2 on page 7-31 shows the contents of the COBOL function, named
TESTCOB.
Example 7-3 on page 7-32 shows the contents of the header file used in this example,
named COBINCLH.
Example 7-4 on page 7-32 shows the contents of the Binder file, named BINDIN.
Example 7-1. C Program that Calls a COBOL Function
/* TESTC */
#pragma inspect, symbols
#include <stdioh> nolist
#include "COBINCLH"
short main (void)
{
short ds;
long dl;
char *tx = "Displayed in COBOL.";
ds = 100;
dl = 40000;
XCOBFUNC (tx, &ds, &dl);
printf ("I'm Back in C and program is ending.\n");
}