pTAL Reference Manual (H06.03+)

LITERALs and DEFINEs
HP pTAL Reference Manual523746-005
6-5
Calling DEFINEs
When a STRUCT item and a DEFINE have the same name, the compiler issues a
warning when the STRUCT item is referenced. In Example 6-3 on page 6-5, DEFINE
myname accesses the structure item1 named in the DEFINE body. The compiler
issues a warning because 2 is assigned to mystruct.yrname, not to
mystruct.myname.
Calling DEFINEs
You call a DEFINE by using its identifier in a statement. The invocation can span
multiple lines.
If you call a DEFINE within an expression, make sure the expression evaluates as you
intend. For instance, if you want the DEFINE body to be evaluated before it becomes
part of the expression, enclose the DEFINE body in parentheses.
Example 6-2. DEFINE Declarations
Parentheses direct the DEFINE body evaluation:
DEFINE value = ( (45 + 22) * 8 / 2 ) #;
Incrementing and decrementing utilities included:
DEFINE increment (x) = x := x + 1 #;
DEFINE decrement (y) = y := y - 1 #;
Loads numbers into specified bit positions:
DEFINE word_val (a, b) = ((a) '<<' 12) LOR (b) #;
Example 6-3. STRUCT and DEFINE Macro Items With the Same Name
PROC myproc MAIN;
BEGIN
DEFINE myname = item1#,
yrname = item2#;
STRUCT mystruct;
BEGIN
INT item1;
INT item2;
INT yrname; ! Structure item has same
END; ! identifier as a DEFINE
mystruct.myname := 1; ! OK: 1 is assigned to mystruct.item1
mystruct.yrname := 2; ! Compiler issues warning;
! 2 is assigned to mystruct.yrname,
! not to mystruct.item2
! More code
END;