annotate docs/ccguide/chap2.chapter @ 565:0e84dcd81835

Several functions ready.
author roug
date Thu, 31 Oct 2002 22:05:32 +0000
parents c43b678c0055
children 7a4d7a896b8f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
1 <chapter>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
2 <title>Characteristics of Compiled Programs</title>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
3
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
4 <section>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
5 <title>The Object Code Module</title>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
6 <para>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
7 The compiler produces position-independent, reentrant 6809 code
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
8 in a standard OS-9 memory module format. The format of an executable
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
9 program module is shown below. Detailed descriptions of each
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
10 section of the module are given on following pages.
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
11 </para>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
12 <informalfigure>
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
13 <screen>
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
14 Module
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
15 Offset
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
16
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
17 +-------------------------------+
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
18 ! !
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
19 ! Module Header !
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
20 ! !
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
21 !-------------------------------!
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
22 ! Execution Offset !
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
23 !-------------------------------!
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
24 ! Permanent Storage Size !
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
25 !-------------------------------!
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
26 ! Data-text Reference Count !
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
27 v v
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
28 : Data-text Reference Offsets :
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
29 ^ ^
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
30 </screen>
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
31 </informalfigure>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
32 <section>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
33 <title>Module Header</title>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
34 <para>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
35 This is a standard module header with the type/language byte set to
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
36 $11 (Program + 6809 Object Code), and the attribute/revision byte
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
37 set to $81 (Reentrant + 1).
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
38 </para>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
39 </section>
530
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
40
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
41 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
42 <title>Execution Offset</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
43 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
44 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
45 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
46
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
47 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
48 <title>Storage Size</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
49 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
50 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
51 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
52
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
53 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
54 <title>Module Name</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
55 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
56 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
57 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
58
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
59 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
60 <title>Information</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
61 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
62 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
63 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
64
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
65 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
66 <title>Executable Code</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
67 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
68 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
69 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
70
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
71 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
72 <title>String Literals</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
73 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
74 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
75 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
76
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
77 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
78 <title>Initializing Data and its Size</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
79 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
80 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
81 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
82
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
83 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
84 <title>Data References</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
85 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
86 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
87 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
88 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
89
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
90 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
91 <title>Memory Management</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
92 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
93 The C compiler and its support programs have default conditions
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
94 such that the average programmer need not be concerned with details
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
95 of memory management. However, there are situations where advanced
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
96 programmers may wish to tailor the storage allocation of a program
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
97 for special situations. The following information explains in
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
98 detail how a C program's data area is allocated and used.
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
99 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
100
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
101 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
102 <title>Typical C Program Memory Map</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
103 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
104 </para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
105 </section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
106
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
107 <section>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
108 <title>Compile Time Memory Allocation</title>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
109 <para>
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
110 </para>
565
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
111 <para>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
112 The following rules can serve as a rough guide to estimate how
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
113 much memory to specify:
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
114 </para>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
115 <orderedlist>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
116 <listitem><para>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
117 The parameter area should be large enough for any anticipated
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
118 command line string.
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
119 </para></listitem>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
120 <listitem><para>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
121 The stack should not be less than 128 bytes and should take
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
122 into account the depth of function calling chains and any
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
123 recursion.
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
124 </para></listitem>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
125 <listitem><para>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
126 All function arguments and local variables occupy stack space
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
127 and each function entered needs 4 bytes more for the return
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
128 address and temporary storage of the calling function's register
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
129 variable.
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
130 </para></listitem>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
131 <listitem><para>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
132 Free memory is requested by the Standard Library I/O
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
133 functions for buffers at the rate of 256 bytes per accessed
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
134 file. The does not apply to the lower level service request I/O
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
135 functions such as "open()", "read()" or "write()" not to
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
136 "stderr" which is always un-buffered, but it does apply to both
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
137 "stdin" and "stdout" (see the Standard Library documentation).
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
138 </para></listitem>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
139 </orderedlist>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
140 <para>
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
141 A good method for getting a feel for how much memory is
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
142 needed by your program is to allow the linker to set the memory size
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
143 to its usually conservative value. Then, if the program runs
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
144 with a variety of input satisfactorily but memory is limited on the
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
145 system, try reducing the allocation at the next compilation. If a
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
146 stack overflow occurs or an "ibrk()" call returns -1, then try
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
147 increasing the memory next time. You cannot damage the system by
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
148 getting it wrong, but data may be lost if the program runs out of
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
149 space at a crucial time. It pays to be in error on the generous
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
150 side.
0e84dcd81835 Several functions ready.
roug
parents: 530
diff changeset
151 </para>
530
c43b678c0055 Mainly section structures added.
roug
parents: 468
diff changeset
152 </section>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
153 </section>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
154 </chapter>