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

Topics:
HP C or HP C++
pTAL
HP C or HP C++
An HP COBOL program can pass numeric arguments to an HP C or HP C++ routine either
by reference or by value.
An HP COBOL program must pass nonnumeric arguments to an HP C or HP C++ routine by
reference.
If the data type of a value parameter differs from the data type of the corresponding formal
parameter, the compiler converts the value of the value parameter to the data type of the
formal parameter. If the value is outside the range of values allowed for the HP C or HP C++
data type, an arithmetic trap occurs.
The compiler cannot convert reference parameters to different data types.
An HP COBOL program can pass an integer (NATIVE-2, NATIVE-4, or NATIVE-8) data item
to an HP C or HP C++ routine either as a reference parameter or by an external declaration.
In both cases, the HP C or HP C++ routine receives the integer as a pointer type.
The GIVING phrase cannot be specified in an ENTER statement that accesses an HP C or
HP C++ function whose type is a pointer.
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 254, 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.
Example 254 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;
}
In Example 255, an HP COBOL program uses external declarations to pass integer data items to
a C routine.
Example 255 Using External Declarations to Pass Integers to C Routine
External declarations in HP COBOL:
Passing Parameters 809