TAL Reference Manual

LITERALs and DEFINEs
TAL Reference Manual526371-001
5-6
Invoking DEFINEs
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; !Okay, 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;
Invoking DEFINEs
You invoke a DEFINE by using its identifier in a statement. The invocation can span
multiple lines.
If you invoke 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.
The following example contrasts expansion of parenthesized and nonparenthesized
DEFINE bodies after the identifiers are used in assignment statements:
DEFINE expr = (5 + 2) #;
j := expr * 4; !Expands to: (5 + 2) * 4;
! assigns 28 to J
DEFINE expr = 5 + 2 #;
j := expr * 4; !Expands to: 5 + 2 * 4;
! assigns 13 to J
DEFINE identifiers are not invoked when specified:
Within a comment
Within a character string constant
On the left side of a declaration