HP C/iX Reference Manual (31506-90011)

34 Chapter3
Data Types and Declarations
Type Qualifiers
When a type qualifier is used with a variable typed by a typedef name, the qualifier is
applied without regard to the contents of the typedef. For example,
typedef int *t_ptr_to_int;
volatile t_ptr_to_int vol_ptr_to_int;
In the example above, the type of vol_ptr_to_int is volatile t_ptr_to_int, which
becomes volatile pointer to int. If the type t_ptr_to_int were substituted directly
in the declaration,
volatile int *ptr_to_vol_int;
the type would be pointer to volatile int.
Type qualifiers apply to objects, not to types. For example,
typedef int *t;
const t *volatile p;
In the example above, p is a volatile pointer to a const pointer to int. volatile applies to
the object p, while const applies to the object pointed to by p. The declaration of p can also
be written as follows:
t const *volatile p;
If an aggregate variable such as a structure is declared volatile, all members of the
aggregate are also volatile.
If a pointer to a volatile object is converted to a pointer to a non-volatile type, and the
object is referenced by the converted pointer, the behavior is undefined.
int const *volatile vpci; Declares a volatile pointer to a constant int.
const *pci; Declares a pointer to a constant int. Since no
type specifier was given, it defaults to int.
Table 3-2. Declarations using const and volatile
Declaration Meaning