const, volatile and restrictconst - Sec. 18.3, Type Qualifiers, and
examples on pp. 172, 250-251, 254-255, 265-266, 478-479volatile - Sec. 20.3, Other Low-Level
Techniques, pp. 523-524restrict- Sec. 17.8, Restricted Pointers, and
the example on p. 543Sec. 4.4.4, ConstSec. 4.4.5, Volatile and Sequence Points (pp.
93-94, see class handout)Sec. 4.4.6, Restrictvoid)
that potentially designates an object; if an lvalue does not
designate an object when it is evaluated, the behavior is
undefined. When an object is said to have a particular
type, the type is specified by the lvalue used to designate the
object. A modifiable
lvalue is an lvalue that does not have array type,
does not have an incomplete type, does not have a
const-qualified type, and if it is a structure or union, does
not have any member (including, recursively, any member or
element of all contained aggregates or unions) with a
const-qualified type.| Expression |
Additional Requirements |
| name |
name must be a variable |
e[k] |
|
(e) |
e must be an lvalue |
e.name |
e must be an lvalue |
e->name |
|
*e |
|
| string-constant |
| Operator |
Requirement |
&
(unary) |
operand must be an lvalue or
a function name |
++ --
(both
prefix and postfix forms) |
operand must be an lvalue |
= +=
-= *= /= %= |
left operand must be an lvalue |
const,
volatile and restrict affect the
modifiability of objects when accessed through lvalues._Atomic.constconst-qualified type
cannot be used to modify an object.const-qualified
type
in
read-only
storage, unless it is also volatile.volatilevolatile-qualified object can have its value
altered in some way not under the control of the compiler.restrictrestrict-qualified pointer is, for the moment,
the only way to refer to the object to which it points.s2 to s1,
assuming there is no overlap in the two memory areas (memcpy)
or allowing overlap (memmove).#include <string.h>
void *memcpy(void * restrict s1, const void * restrict s2,
size_t n);
void *memmove(void * s1, const void * s2, size_t n);restrict is only a hint to the compiler, which is
free to ignore it.restrict should be taken seriously by the
programmer, as it clarifies your thinking about function design
and usage.restrict's effect,
see the C Standard. Otherwise, see CP:AMA Sec. 17.8.extern const volatile int real_time_clock;real_time_clock
(it's const) but something else could (it's volatile).