COBOL Manual for TNS and TNS/R Programs

Calling Other Programs and Routines
HP COBOL Manual for TNS and TNS/R Programs522555-006
23-18
Restrictions on Calling Non-COBOL Routines
HP C++ Function Name Consideration
When a COBOL program calls a function compiled by HP C++, the function definition
must include the extern "C" specification for the function name to be used in its original
form. HP C++, by default, adjusts function names to accommodate generic functions
and class methods. For example, a definition such as:
void EXT(char *p) {}
results in the creation of an entry point called EXT_FPc; however, a definition of the
form:
extern "C" void EXT(char *p) {}
produces an entry point called EXT.
This is true for both COBOL85 and NMCOBOL, in both the Guardian environment and
the OSS environment.
FORTRAN Routines
Only TNS HP COBOL programs in the Guardian environment can call FORTRAN
routines. If you want your native HP COBOL program to call a FORTRAN routine,
convert the FORTRAN routine to native HP COBOL, native HP C, native HP C++, or
pTAL.
In the non-CRE environment, if an HP COBOL program calls a FORTRAN routine,
process termination must be handled by an HP COBOL routine. If execution terminates
in FORTRAN code, the run-time routines do not have a chance to complete any
possible pending input-output operations, and lines of printer or terminal output are
likely to be lost. This restriction does not apply in the CRE, because HP COBOL and
FORTRAN routines can share IN, OUT, and $RECEIVE.
HP C Code:
#include <stdio.h> nolist
extern char MYVAR[21];
void SHOWEXT(void){
int i;
/* In the Guardian environment, the call to fopen_std_file
is needed because the main program is in HP COBOL.
In the OSS environment, comment out or delete the call to fopen_std_file */
fopen_std_file(1, 1); /* stdout, die_on_error = TRUE */
printf(" Input value: %s\n", MYVAR);
for ( i=0; i < 20; i++) MYVAR[i] -= 32; /* shift case */
printf(" Output value: %s\n", MYVAR);
}
Example 23-2. HP COBOL and HP C Programs Sharing Data