6.6. Qualifiers and derived types
Arrays, structures and unions are ‘derived from’ (contain) other
types; none of them may be derived from incomplete types. This means that
a structure or union cannot contain an example of itself, because its own
type is incomplete until the declaration is complete. Since a pointer to an
incomplete type is not itself an incomplete type, it can be used in
the derivation of arrays, structures and unions.
If any of the types that these things are derived from are qualified with
const or volatile , they do not inherit
that qualification. This means that if a structure contains
a const object, the structure itself is not qualified with
const and any non-const members can still be modified. This is what you
would expect. However, the Standard does says that if any derived type
contains a type that is qualified with const (or recursively
any inner type does) then it is not modifiable—so a structure that
contains a const cannot be on the left-hand side of an assignment
operator.
|
Printer-friendly version
The C Book
This book is published as a matter of historical interest.
Please read the
copyright and disclaimer information.
GBdirect Ltd provides up-to-date training and consultancy in
C,
Embedded C,
C++
and a wide range of
other subjects based on
open standards if you happen to be interested.
|