CMPSC 311, Introduction to Systems Programming

const, volatile and restrict



Reading
Class handout



An object (in C) is a region of memory that can be examined and stored into.

An lvalue is an expression that refers to an object in such a way that the object may be examined or altered.
Legal lvalue expressions in C

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


These are not lvalues - array names, functions, enumerated constants, assignment expressions, casts, and function calls.
The following operators require an lvalue operand.

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

The type qualifiers const, volatile and restrict affect the modifiability of objects when accessed through lvalues.
const
volatile
restrict
Example (CP:AMA, p. 479)
Reminder



Last revised, 15 Feb. 2013