pTAL Conversion Guide

Data Allocation
pTAL Conversion Guide527302-002
5-8
Valid Uses of the VOLATILE Attribute
Volatile Simple Variables
Each time your program references a volatile simple variable or a volatile simple
structure field, the value of the variable is read from or written to memory.
Volatile Simple Pointers
When your program references a volatile simple pointer (a volatile pointer to
nonstructure data), both the pointer itself and the data that the pointer references are
volatile, regardless of the type of pointer, the type of data, or the location of the data.
Example 5-4. Volatile Simple Variables
VOLATILE INT c;
INT d;
INT e;
d := c + .01 * c; ! Each reference to c causes a memory read.
! Because another process could be accessing
! c asynchronously, the value of c could
! differ for the two read operations
e := d; ! The value of c + .01 * c is stored in d,
! and, because d is not volatile, is also
! stored in e. If there is a copy of the
! value of d in a register, the object code
! does not need to reread the value of d
! from memory in the assignment e := d
! because d is not volatile
Example 5-5. Volatile Simple Pointers (page 1 of 2)
INT i;
INT a;
INT b[0:9
VOLATILE INT .p1 := @a;
VOLATILE INT .p2 := @b
i := p1; ! Pointer p1 and the data p1 references, a, are
! treated as volatile
i := a; ! Direct reference to a is not treated as
! volatile even though p1 still points to it,
! because a is not declared volatile
i := p2[a]; ! For each reference to p2[a], the program:
! * Reads from memory the value of pointer p2
! * Adds the value of a (which can be kept in a
! register because a is not volatile)
! * Reads from memory the value that p2[a]
! references