1 <!DOCTYPE HTML PUBLIC
"-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995, 1996 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
7 <link rev=
"owner" href=
"mailto:scs@eskimo.com">
8 <link rev=
"made" href=
"mailto:scs@eskimo.com">
9 <title>section
6.2: Structures and Functions
</title>
10 <link href=
"sx9a.html" rev=precedes
>
11 <link href=
"sx9c.html" rel=precedes
>
12 <link href=
"sx9.html" rev=subdocument
>
15 <H2>section
6.2: Structures and Functions
</H2>
18 we'll begin playing with structures
19 more or less as if they were ordinary variables
20 such as we've been using all along
21 (which they more or less are).
24 declare variables of structure type,
25 declare functions which accept structures as parameters and return them,
26 declare pointers to structures,
27 take the address of a structure
28 (creating a pointer-to-structure)
30 and assign structures.
31 </p><p>Notice that when we declare something as ``a structure type,''
32 we always have to say
<em>which
</em> structure type,
33 usually by using the struct tag.
34 If we've set up a ``point'' structure as above,
35 then to declare a variable of this type,
37 <pre> struct point thepoint;
39 <pre> struct thepoint; /* WRONG */
41 <pre> point thepoint; /* WRONG */
42 </pre>would be errors.
43 </p><p>The above list of things the language lets us do with structures
44 lets us keep them and move them around,
45 but there isn't really anything defined by the language
46 that we can
<em>do
</em> with structures.
47 It's up to us to define any operations on structures,
48 usually by writing functions.
49 (The
<TT>addpoint
</TT> function on page
130 is a good example.
50 It will make a bit more sense
51 if you think of it as adding not isolated points,
54 [We can't add Seattle plus Los Angeles,
56 (two miles south, one mile east)
58 (one mile east, two miles north).])
61 how safe are the
<TT>min()
</TT> and
<TT>max()
</TT>
62 macros defined at the top of page
131,
63 with respect to the criteria
64 discussed on pages
15 and
16
67 on section
4.11.2 (page
90 in the text)?
68 </p><p>The precise meaning of the ``shorthand''
<TT>-
></TT> operator
69 is that
<TT>sp-
>m
</TT> is,
74 for any structure pointer
<TT>sp
</TT>
75 and member
<TT>m
</TT> of the pointed-to structure.
79 <a href=
"sx9a.html" rev=precedes
>prev
</a>
80 <a href=
"sx9c.html" rel=precedes
>next
</a>
81 <a href=
"sx9.html" rev=subdocument
>up
</a>
82 <a href=
"top.html">top
</a>
85 This page by
<a href=
"http://www.eskimo.com/~scs/">Steve Summit
</a>
86 //
<a href=
"copyright.html">Copyright
</a> 1995,
1996
87 //
<a href=
"mailto:scs@eskimo.com">mail feedback
</a>