pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
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;
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 26 Parenthesized and Nonparenthesized DEFINE Bodies
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 called when specified:
• Within a comment
• Within a character string constant
• On the left side of a declaration
For example, the following declaration can call a DEFINE named y but not a DEFINE named
x:
INT x := y;
How the Compiler Processes DEFINEs
The compiler does not allocate storage for DEFINE declarations. When the compiler encounters a
statement using a DEFINE identifier, the compiler expands the DEFINE declaration as follows:
• It replaces the DEFINE identifier with the DEFINE body, replaces formal parameters with actual
parameters, and compiles the resulting declaration.
• It expands quoted character strings intact.
• It expands actual parameters after instantiation. Depending on the order of evaluation, the
expansion can change the scope of a DEFINE declaration.
• Emits machine instructions at the appropriate processing interval.
If the DEFEXPAND directive is active, the compiler lists each expanded DEFINE declaration in the
compiler listing following the invocation of the DEFINE. The expanded listing includes:
• The DEFINE body, excluding comments
• Parameters to the DEFINE declaration
Passing Actual Parameters to DEFINEs
If the DEFINE declaration has formal parameters, supply the actual parameters when you use the
DEFINE identifier in a statement.
100 LITERALs and DEFINEs