5.0 Expressions 439
As an example,
typedef struct
{
float x;
float y;
} Point;
associates the name Pointwith a structure containing two floating-point members called
xand y.Variables can subsequently be declared to be of type Point, as in
Point origin = { 0.0, 0.0 };
4.6 Type Modifiers const,volatile, and restrict
The keyword constcan be placed before a type declaration to tell the compiler that the
value cannot be modified. So the declaration
const int x5 = 100;
declares x5to be a constant integer (that is, it won’t be set to anything else during the
program’s execution).The compiler is notrequired to flag attempts to change the value
of a constvariable.
The volatilemodifier explicitly tells the compiler that the value changes (usually
dynamically).When a volatilevariable is used in an expression, its value is accessed
each place it appears.
To declare port17to be of type “volatile pointer to char,” w rite
volatile char *port17;
The restrictkeyword can be used with pointers. It is a hint to the compiler for opti-
mization (like the registerkeyword for variables).The restrictkeyword specifies to
the compiler that the pointer is the only reference to a particular object; that is, it is not
referenced by any other pointer within the same scope.The lines
int * restrict intPtrA;
int * restrict intPtrB;
tell the compiler that for the duration of the scope in which intPtrA and intPtrBare
defined, they will never access the same value.Their use for pointing to integers (in an
array, for example) is mutually exclusive.
5.0 Expressions
Va r iable names, function names, array names, constants, function calls, array references,
and structure and union references are all considered expressions. Applying a unary oper-
ator (where appropriate) to one of these expressions is also an expression, as is combin-
ing two or more of these expressions with a binary or ternary operator. Finally, an
expression enclosed within parentheses is also an expression.
20 0672326663 AppA 6/10/04 2:01 PM Page 439