Section 2: Compiler
69
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
The volatile type specifier observes the same declaration usage rules as the
const type specifier (see section 2.9.8 Const Type Specifier); it can be used in
conjunction with the const type specifier. The following declarations define a
volatile int, a constant volatile int, and a volatile pointer to a constant volatile
pointer to a pointer to a volatile double, respectively:
volatile int a;
volatile const int b;
volatile double ** volatile const * volatile c;
The second declaration above could be used for a resource such as a real-time
clock; the compiler does not know when the value of a real-time clock changes,
and a program should not attempt to modify it.
A pointer to a nonvolatile object can be assigned to a pointer to either a volatile
or nonvolatile object; however, a pointer to a volatile object can only be assigned
to a pointer to a volatile object. These pointer assignment rules, which are
analogous to the rules for constant pointers described above, were established to
help prevent accidental references of volatile objects with dereferenced pointers
to nonvolatile objects.
2.9.10. Touch
Operator
The
_touch(*
pointer_to_volatile_argument) operator uses the test instruction,
tst, to “touch” the memory location pointed to by
pointer_to_volatile_argument. In
embedded systems design, it is often necessary to touch an address-mapped
piece of hardware — e.g., to increment a counter or set a latch. The argument to
_touch( ) must be a dereferenced pointer to a volatile integer type object;
otherwise, _touch( ) behaves as an ordinary function.
2.9.11.
Void Type Specifier
An expression of type void has no value associated with it. Such an expression
can be neither referenced nor converted (implicitly or explicitly) to another type.
The void type specifier is most frequently used in the declaration of functions
that return no values. It is illegal for a void function to return a value or for the
return value of a void function to be used in an expression. The void type can
also be used to indicate that the value of an expression is ignored. For example,
the following function, which returns no value, uses a void cast to discard the
return value of the printf function:
void report_error(int error, int line)
{
(void)printf("Error %d on line: %d\n", error, line);
}