TAL Reference Manual
LITERALs and DEFINEs
TAL Reference Manual—526371-001
5-5
Examples of DEFINE Declarations
•
If expanded DEFINEs must produce correct TAL constructs. To list the expanded
DEFINEs in the compiler listing, specify the DEFEXPAND directive before the
DEFINE declarations. (For more information, see Compiler Action
on page 5-7.)
Examples of DEFINE Declarations
1. This example uses parentheses to direct the DEFINE body evaluation:
DEFINE value = ( (45 + 22) * 8 / 2 ) #;
2. This example provides incrementing and decrementing utilities:
DEFINE increment (x) = x := x + 1 #;
DEFINE decrement (y) = y := y - 1 #;
3. This example loads numbers into particular bit positions. To ensure proper
evaluation, parentheses enclose each parameter used in an expression:
DEFINE word_val (a, b) = ((a) '<<' 12) LOR (b) #;
4. This example shows a CODE (DECS) statement, which is equivalent to the DECS
directive. This example is not portable to future software platforms:
DEFINE call_it (x, y) =
BEGIN
STACK x;
STACK y;
CODE (PUSH %711);
CODE (DPCL);
CODE (DECS 2); !Equivalent to DECS directive
END #;
call_it (a, b); !Expands to: STACK a;
! STACK b;
! CODE (PUSH %711);
! CODE (DPCL);
! ?DECS 2
5. In this example, DEFINE MYNAME accesses the structure item named in the
DEFINE body. However, the compiler issues a warning because 2 is assigned to
MYSTRUCT.YRNAME, not to MYSTRUCT.ITEM2:
Note. if you use a DEFINE to name and access a structure item, the DEFINE identifier must
be unique among the identifiers of all structure items in the compilation unit. Conversely, if you
use the DEFINE identifier to access a structure item and some other structure item has the
name identifier as the DEFINE, you access the other structure item and the compiler issues a
warning. To access structure bit fields smaller than a byte, use UNSIGNED declarations
instead of DEFINEs.