C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
7-18
Variables and Parameters
STRING and char Variables
TAL STRING and C char simple variables each occupy one byte of a word. These are
STRING and char compatibility guidelines:
Share variables of type TAL STRING and C char by using pointers.
Declare TAL STRING and C char formal parameters as reference parameters to
avoid these value-parameter incompatibility:
°
When you pass a STRING parameter to a C routine, the actual byte value
occupies the left byte of the word allocated for the C char formal parameter.
°
When you pass a char parameter to a TAL routine, the actual byte value
occupies the right byte of the word allocated for the TAL STRING formal
parameter.
For example, if you declare a TAL STRING formal parameter as a value parameter
rather than as a reference parameter, the TAL routine can access the C char actual
parameter only by explicitly referring to the right byte of the word allocated for the
STRING formal parameter:
PROC sample (s);
STRING s; !Declare TAL STRING parameter as a
BEGIN ! value (not reference) parameter
STRING dest;
dest := s[1]; !Refer to right byte of word
END:
Arrays
TAL and C arrays differ:
* TAL structures can emulate multidimensional C arrays, as discussed in Multidimensional Arrays on
page 7-20.
To declare compatible TAL and C arrays:
Use data types and alignments that satisfy both compilers.
Declare TAL arrays that have a lower bound of 0.
Declare one-dimensional C arrays.
Declare indirect TAL arrays.
Characteristic TAL Array C Array
Lower bound Any integer Always zero
Dimensions One dimension * One or more dimensions
Direct or indirect Direct or indirect Indirect only
Byte or word addressing STRING arrays and
extended indirect arrays are
byte addressed; all other
arrays are word addressed
char arrays and large-
memory-model arrays are
byte addressed; all other
arrays are word addressed