COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

Example 251 HP COBOL and HP C Programs Sharing Data
HP COBOL Code:
* The SEARCH directive references the HP C object file.
?SYMBOLS; SEARCH SHOWEXTO
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST-EXTERNAL.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES. SYMBOLIC NULLCHAR IS 1.
DATA DIVISION.
EXTENDED-STORAGE SECTION.
01 MYVAR EXTERNAL.
05 DATA-01 PIC X(20).
05 NULL-TERM PIC X.
PROCEDURE DIVISION.
STARTIT.
MOVE "abcdefghijlmnopqrstu" TO DATA-01.
MOVE NULLCHAR TO NULL-TERM.
ENTER C "SHOWEXT".
DISPLAY "Back in COBOL: " DATA-01.
HP C Code:
#include 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);
}
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 in both the Guardian environment and the OSS environment.
Passing Parameters
Topics:
Addressing Modes
What HP COBOL Can Pass by Content
What HP COBOL Can Pass by Reference
804 Calling Other Programs and Routines