C/C++ Programmer's Guide (G06.25+)
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
7-23
Variables and Parameters
Bit-Field Manipulation
You can manipulate bit fields in both TAL and C.
In TAL, you can use either:
•
Built-in bit-extraction and bit-deposit operations
•
Bit-wise operators LAND and LOR
In C, you can use either:
•
Bit-wise operators & (and) and | (or)
•
Defines
The following TAL bit-deposit operation and C bit-wise operation are equivalent:
TAL Code C Code
INT x := -1; short a = -1;
INT y := 0; short b = 0;
short temp = 0;
PROC example;
BEGIN void example ()
y.<0:2> := x.<10:12>; {
END; /* you can combine these */
/* with wider margins */
temp = a & 070;
temp = temp << 10;
b = (b & 017777)|temp;
}
Bit extractions and bit deposits are not portable to future software platforms.
UNSIGNED Variables and Packed Bit Fields
In general, TAL UNSIGNED simple variables in structures are compatible with C
unsigned packed bit fields (which appear only in structures). You cannot, however,
pass C bit fields as reference parameters to TAL routines.
The following UNSIGNED variables and C unsigned bit fields are compatible:
TAL Code C Code
STRUCT stuffed (
*
); struct stuffed;
BEGIN {
INT x; int x;
UNSIGNED(1) a; unsigned a : 1;
UNSIGNED(5) b; unsigned b : 5;
UNSIGNED(3) c; unsigned c : 3;
UNSIGNED(4) d; unsigned d : 4;
UNSIGNED(9) e; unsigned e : 9;
UNSIGNED(2) f; unsigned f : 2;
END; };
STRUCT packed (stuffed); struct stuffed PACKED;