COBOL Manual for TNS and TNS/R Programs
Calling Other Programs and Routines
HP COBOL Manual for TNS and TNS/R Programs—522555-006
23-28
Passing Parameters to Non-COBOL Routines
•
When the formal parameter for an HP C or HP C++ function is a scalar variable, its
type designation cannot include the modifier “unsigned.” When the COBOL
parameter is numeric, the type “char” is included in this prohibition, because the
HP C or HP C++ compiler interprets it as equivalent to the type “unsigned char.”
The type “signed char” is acceptable. When the COBOL parameter is not numeric,
the type “char” is acceptable.
For more information about HP C or HP C++ routines and modules, see the C/C++
Programmer’s Guide and the Guardian Native C Library Calls Reference Manual.
In Example 23-5, an HP COBOL program uses reference parameters to pass integer
data items to a C routine. On return from the ENTER statement in the HP COBOL
code, SQ contains the product of PAR1, PAR2, and PAR3, and the value of PAR3 is
25.
In Example 23-6, an HP COBOL program uses external declarations to pass integer
data items to a C routine. If the C routine was compiled for the small memory model,
the values are manipulated with explicit casts to pointers.
Example 23-5. Using Reference Parameters to Pass Integers to C Routine
HP COBOL code:
01 PARAMS.
03 PAR1 USAGE IS NATIVE-2.
03 PAR2 USAGE IS NATIVE-4.
03 PAR3 USAGE IS NATIVE-8.
01 SQ USAGE IS NATIVE-8.
...
ENTER C "blog" USING PAR1 PAR2 PAR3 GIVING SQ
...
C code:
long long blog (int *a, long *b, long long *c)
{
long long result;
...
result = *a * *b * *c;
c = 25;
return result;
}
Example 23-6. Using External Declarations to Pass Integers to C
Routine (page 1 of 2)
External declarations in HP COBOL:
01 FLIP USAGE IS NATIVE-2 EXTERNAL.
01 FLAP USAGE IS NATIVE-4 EXTERNAL.
01 FLOP USAGE IS NATIVE-8 EXTERNAL.