pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
D RETURN, RETURNSCC, and C/C++ on TNS/E
Read this appendix if you write or call pTAL procedures that:
• Return both:
A traditional function value by means of the RETURN statement◦
◦ An unrelated condition code value by means of the RETURNSCC attribute
• And are called by C or C++ procedures
On the TNS architecture, a TAL procedure can return both a traditional function value and an
unrelated condition code value. Both return values are accessible after the procedure call. pTAL
procedures emulate this behavior on both the TNS/R and TNS/E architectures, but C/C++
procedures do not.
On the TNS/R architecture, if a C/C++ procedure calls a pTAL procedure that returns both a
traditional function value and a condition code value, the C/C++ compiler issues an error message.
Some programmers work around this C/C++ compile-time error by writing C/C++ prototypes that
rely on the knowledge that on the TNS/R architecture, pTAL object code stores the two return values
in a single 64-bit value. After the C/C++ procedure calls the pTAL procedure, it extracts from the
64-bit value either both return values (see Example 367 (page 528)) or only the traditional function
value (see Example 368 (page 529)).
CAUTION: C/C++ prototypes such as these are not guaranteed to work on the TNS/R architecture,
and extracting only the traditional function value (as in Example 368 (page 529)) does not work
on the TNS/E architecture.
The EpTAL compiler issues a warning whenever a pTAL procedure returns both a traditional function
value and a condition code value. To migrate such a procedure to TNS/E, HP recommends that
you:
1. Write a pTAL shell procedure that returns the two values in the way that C/C++ returns them
(in Example 369 (page 529), this procedure is P_SHELL).
2. Change the alias of the C/C++ prototype to the name of the pTAL shell procedure in
FIX_THIS_LINK. (This change eliminates the need to change the calls to this prototype.)
3. Retire the original pTAL procedure linkage name. This allows the eld utility to identify any
uses of unchanged C/C++ prototypes, instead of producing an executable program that uses
the old prototypes (because the eld utility does not produce an executable program if there
are unresolved procedure references).
Example 367 C Procedure Extracting Two pTAL Return Values from a 64-Bit Value (Works
Only on TNS/R Systems—Not Recommended)
pTAL procedure with two return values:
int proc p (i, j, k) returnscc;
int(16) i;
int(32) .ext j;
int(64) k;
begin
...
return i, j < k; ! Traditional function value is the value of i.
! Expression j < k sets condition code.
end;
C/C++ prototype for accessing pTAL procedure:
_tal _alias ("P") long long some_name (short i, int* j, long long k);
C/C++ code that captures the 64-bit value:
528 RETURN, RETURNSCC, and C/C++ on TNS/E