pTAL Conversion Guide

Data Allocation
pTAL Conversion Guide527302-002
5-9
Valid Uses of the VOLATILE Attribute
Volatile Structure Pointers
When your program references a volatile pointer to structure data, the pointer itself is
always treated as volatile, but the data that the pointer references (the structure field)
is treated as volatile only if:
The structure field itself specifies the VOLATILE attribute (as the field n does in
Example 5-6 on page 5-9).
The structure field (which need not specify the VOLATILE attribute) is the operand
in a scan, move, or string-comparison operation.
Volatile Parameters
A volatile variable is treated as volatile when its value or address is passed to a
procedure. Within a called procedure, a formal parameter is treated as volatile only if
the formal parameter specification specifies VOLATILE, independent of whether or not
the actual parameter specifies VOLATILE.
i := p2[p1]; ! The data referenced by p2[p1] is the same as
! p2[a] of the preceding example, but both
! p1 and p2 are volatile. The program reads
! from memory p1, p2, a, and the element of
! array b that p1 references
Example 5-6. Volatile Structure Pointers
INT i;
STRUCT s;
BEGIN
INT m; ! Field m is never treated as volatile
VOLATILE INT n; ! Field n is always treated as volatile
END
VOLATILE INT .s1(s) := @s; ! Pointer s1 is volatile
INT .s2(s) := @s; ! Pointer s2 is not volatile
i := s1.m; ! The value of pointer s1 is always read from
! memory, but the value of field s1.m might
! be maintained in a register
i := s1.n; ! The value of pointer s1 is always read from
! memory, as is the value of field s1.n
i := s2.n; ! The value of pointer s2 might or might not
! be read from memory, but having read the
! pointer, the field s2.n is always read
! from memory
Example 5-5. Volatile Simple Pointers (page 2 of 2)