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.1: Basics of Structures
</title>
10 <link href=
"sx9.html" rev=precedes
>
11 <link href=
"sx9b.html" rel=precedes
>
12 <link href=
"sx9.html" rev=subdocument
>
15 <H2>section
6.1: Basics of Structures
</H2>
17 <p>Don't get too excited about the prospect of doing graphics
19 no one standard or portable way of doing it,
20 so the points and rectangles we're going to be discussing
21 must remain abstract for now
22 (we won't be able to plot them out).
24 </p><p>To summarize the syntax of structure declarations:
25 A structure declaration has about four parts,
26 most of them optional:
27 the keyword
<TT>struct
</TT>,
28 a
<dfn>structure tag
</dfn> (optional),
29 a brace-enclosed list of declarations for the
31 (also called ``fields'' or ``components'')
32 of the structure (optional),
33 and a list of variables of the new structure type (optional).
34 The arrangement looks like this:
35 <pre> struct
<I>tag
</I> {
36 <I>member declarations
</I>
37 }
<I>declared variables
</I> ;
38 </pre>Normally, a structure declaration defines either a tag and the members,
39 or some variables based on an existing tag,
40 or sometimes all three at once.
42 we might first declare a structure:
43 <pre> struct point { /*
1 */
47 </pre>and then some variables of that type:
48 <pre> struct point here, there; /*
2 */
49 </pre>Or, we could combine the two:
50 <pre> struct point { /*
3 */
54 </pre>The list of members
56 describes what the new structure ``looks like inside.''
61 the list of variables of this new type
63 and which the rest of the program will use.
66 is just an arbitrary name for the structure type itself
67 (not for any variable we're defining).
68 The tag is used to associate a structure definition
70 with a later declaration of variables of that same type
72 </p><p>One thing to beware of:
73 when you declare the members of a structure without defining any variables,
75 the trailing semicolon,
80 the compiler will wait until the next thing it finds in your source file,
81 and try to define
<em>that
</em>
82 as a variable or function of the structure type.)
86 <a href=
"sx9.html" rev=precedes
>prev
</a>
87 <a href=
"sx9b.html" rel=precedes
>next
</a>
88 <a href=
"sx9.html" rev=subdocument
>up
</a>
89 <a href=
"top.html">top
</a>
92 This page by
<a href=
"http://www.eskimo.com/~scs/">Steve Summit
</a>
93 //
<a href=
"copyright.html">Copyright
</a> 1995,
1996
94 //
<a href=
"mailto:scs@eskimo.com">mail feedback
</a>