Hardware Reference
In-Depth Information
unsigned
int date;
unsigned
char rev;
} card;
where the variable card is of type catalog_tag .
A structure definition that is not followed by a list of variables reserves no storage; it merely
describes a template or the shape of a structure. If the declaration is tagged (i.e., has a name),
however, the tag can be used later in definitions of instances of the structure. For example, sup-
pose we have the following structure declaration:
struct point {
int x;
int y;
};
We can then define a variable pt of type point as follows:
struct point pt;
A member of a particular structure is referred to in an expression by a construction of the form
structure-name.member or structure-pointer member
The structure member operator . connects the structure name and the member name. As
an example, the square of the distance of a point to the origin can be computed as follows:
long integer sq_distance;
. . .
sq_distance 5 pt.x * pt.x 1 pt.y * pt.y;
Structures can be nested. One representation of a circle consists of the center and radius, as
shown in Figure 5.1.
y
Radius
Center
x
Figure 5.1 A circle
This circle can be defined by
struct circle {
struct
point
center;
unsigned
int
radius;
};
 
Search WWH ::




Custom Search