pTAL Conversion Guide

Data Allocation
pTAL Conversion Guide527302-002
5-11
Undefined Uses of the VOLATILE Attribute
Undefined Uses of the VOLATILE Attribute
The effect of the VOLATILE attribute is undefined for a volatile variable that is the
target of an intermediate store operation. Use separate assignment statements to
ensure that the VOLATILE attribute has the intended effect.
Difference Between Volatile Data and Atomic Operations
A volatile data item is always maintained in memory (as opposed to a register), but the
object code might use more than one machine instruction to access the data item each
time your source code reads or writes it.
When you access a variable using an atomic operation, that access is treated as if you
had declared the variable volatile—its value is read from or written to memory—but an
atomic operation completes before any other process, or other code within the same
process (for example, a trap handler), accesses the data. If your program has variables
that must be accessed in one memory fetch or one memory store, use one or more of
the atomic operations in Table 18-2 on page 18-4.
VOLATILE INT a[0:9]; ! Direct array
VOLATILE INT .b[0:9]; ! Indirect array
VOLATILE INT .EXT c[0:9]; ! Extended array
VOLATILE INT i = 'P' := "ABCD"; ! Read-only array
Example 5-9. Ensuring That VOLATILE is Effective
VOLATILE INT a;
INT b;
INT c;
b := a := c + 1; ! VOLATILE attribute of a might not be
! honored when assigning the value of
! c + 1 to a
a := a + 1; ! VOLATILE attribute of a is honored
b := a; ! VOLATILE attribute of a is honored
Example 5-8. Invalid Uses of the VOLATILE Attribute (page 2 of 2)