TAL Programmer's Guide

TAL and C Guidelines
Mixed-Language Programming
096254 Tandem Computers Incorporated 17–29
UNSIGNED Variables and Packed Bit Fields
In general, TAL UNSIGNED simple variables in structures are compatible with C
unsigned packed bit fields (which only appear 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;
When the WIDE pragma is not specified, the C compiler normally packs adjacent bit
fields in a 16-bit word. When the WIDE pragma is specified, the C compiler normally
packs adjacent bit fields in a 32-bit word.
TAL UNSIGNED(1–16) and C bit fields of like size are compatible. TAL
UNSIGNED(17–31) and C bit fields of like size are compatible.
The TAL compiler always packs adjacent UNSIGNED simple variables in 16-bit words
as follows:
It starts the first UNSIGNED variable on a word boundary.
It packs each successive UNSIGNED variable in the remaining bits of the same
word as the preceding UNSIGNED variable if:
The variable contains 1 to 16 bits and fits in the same word
The variable contains 17 to 31 bits and fits in the same word plus the next
word
If an UNSIGNED variable does not fit in the same word or doubleword, the
compiler starts the variable on the next word boundary.
The operator you use determines whether UNSIGNED values are signed or unsigned:
UNSIGNED(3) x; !TAL code
UNSIGNED(3) y;
IF x + y ... ; !Signed operation
IF x '+' y ... ; !Unsigned operation
UNSIGNED arrays that contain 8-bit or 16-bit elements are compatible with C arrays
that contain elements of like size. UNSIGNED arrays that contain 1-bit, 2-bit, or 4-bit
elements are incompatible with C arrays.