466
|
1 <chapter>
|
|
2 <title>The C Compiler System</title>
|
|
3
|
|
4 <section>
|
|
5 <title>Introduction</title>
|
|
6 <para>
|
468
|
7 The "C" programming language is rapidly growing in popularity
|
|
8 and seems destined to become one of the most popular programming
|
|
9 languages used for microcomputers. The rapid rise in the use of C
|
|
10 is not surprising. C is an incredibly versatile and efficient
|
|
11 language that can handle tasks that previously would have required
|
|
12 complex assembly language programming.
|
466
|
13 </para>
|
530
|
14 <para>
|
|
15 C was originally developed at Bell Telephone Laboratories as an
|
|
16 implementation language for the UNIX operating system by Brian
|
|
17 Kernighan and Dennis Ritchie. They also wrote a book titled <quote>The
|
|
18 C Programming Language</quote> which is universally accepted as the standard
|
|
19 for the language. It is an interesting reflection on the language
|
|
20 that although no formal industry-wide <quote>standard</quote> was ever developed
|
|
21 for C, programs written in C tend to be far more portable between
|
|
22 radically different computer systems as compared to so-called
|
|
23 <quote>standardized</quote> languages such as BASIC, COBOL, and PASCAL. The
|
|
24 reason C is so portable is that the language is so inherently
|
|
25 expandable that is some special function is required, the user can
|
|
26 create a portable extension to the language, as opposed to the
|
|
27 common practice of adding additional statements to the language.
|
|
28 For example, the number of special-purpose BASIC dialects defies all
|
|
29 reason. A lesser factor is the underlying UNIX operating system,
|
|
30 which is also sufficiently versatile to discourage bastardization of
|
|
31 the language. Indeed, standard C compilers and Unix are intimately
|
|
32 related.
|
|
33 </para>
|
|
34 <para>
|
|
35 Fortunately, the 6809 microprocessor, the OS-9 operating
|
|
36 system, and the C language form an outstanding combination. The
|
|
37 6809 was specifically designed to efficiently run high-level
|
|
38 languages, and its stack-oriented instruction set and versatile
|
|
39 repertoire of addressing modes handle the C language very well. As
|
|
40 mentioned previously, UNIX and C are closely related, and because
|
|
41 OS-9 is derived from UNIX, it also supports C to the degree that
|
|
42 almost any application written in C can be transported from a UNIX
|
|
43 system to an OS-9 system, recompiled, and correctly executed.
|
|
44 </para>
|
466
|
45 </section>
|
|
46 <section>
|
468
|
47 <title>The Language Implementation</title>
|
466
|
48 <para>
|
468
|
49 OS-9 C is implemented almost exactly as described in 'The C
|
|
50 Programming Language' by Kernighan and Ritchie (hereafter referred
|
|
51 to as K&R).
|
|
52 </para>
|
|
53 <para>
|
|
54 Allthough this version of C follows the specification faithfully,
|
|
55 there are some differences. The differences mostly reflect
|
|
56 parts of C that are obsolete or the constraints imposed by memory
|
|
57 size limitations.
|
466
|
58 </para>
|
530
|
59 </section>
|
472
|
60
|
530
|
61 <section>
|
|
62 <title>Differences from the K & R Specification</title>
|
|
63 <para>
|
|
64 </para>
|
472
|
65 </section>
|
530
|
66
|
|
67 <section>
|
|
68 <title>Enhancements and Extensions</title>
|
|
69
|
|
70 <section>
|
|
71 <title>The <quote>Direct</quote> Storage Class</title>
|
|
72 <para>
|
|
73 </para>
|
|
74 </section>
|
|
75
|
|
76 <section>
|
|
77 <title>Embedded Assembly Language</title>
|
|
78 <para>
|
|
79 </para>
|
|
80 </section>
|
|
81
|
|
82 <section>
|
|
83 <title>Control Character Escape Sequences</title>
|
|
84 <para>
|
|
85 </para>
|
|
86 </section>
|
|
87 </section>
|
|
88
|
|
89 <section>
|
|
90 <title>Implementation-dependent Characteristics</title>
|
|
91 <para>
|
|
92 </para>
|
|
93
|
|
94 <section>
|
|
95 <title>Data Representation and Storage Requirements</title>
|
|
96 <para>
|
|
97 </para>
|
|
98 </section>
|
|
99
|
|
100 <section>
|
|
101 <title>Register Variables</title>
|
|
102 <para>
|
|
103 </para>
|
|
104 </section>
|
|
105
|
|
106 <section>
|
|
107 <title>Access To Command Line Parameters</title>
|
|
108 <para>
|
|
109 </para>
|
|
110 </section>
|
|
111 </section>
|
|
112
|
|
113 <section>
|
|
114 <title>System Calls and the Standard Library</title>
|
|
115
|
|
116 <section>
|
|
117 <title>Operating System Calls</title>
|
|
118 <para>
|
|
119 </para>
|
|
120 </section>
|
|
121
|
|
122 <section>
|
|
123 <title>The Standard Library</title>
|
|
124 <para>
|
|
125 </para>
|
|
126 </section>
|
|
127 </section>
|
|
128
|
|
129 <section>
|
|
130 <title>Run-time Arithmetic Error Handling</title>
|
|
131 <para>
|
|
132 </para>
|
|
133 </section>
|
|
134
|
|
135 <section>
|
|
136 <title>Achieving Maximum Program Performance</title>
|
|
137 <para>
|
|
138 </para>
|
|
139
|
|
140 <section>
|
|
141 <title>Programming Considerations</title>
|
|
142 <para>
|
|
143 </para>
|
|
144 </section>
|
|
145
|
|
146 <section>
|
|
147 <title>The Optimizer Pass</title>
|
|
148 <para>
|
|
149 </para>
|
|
150 </section>
|
|
151
|
|
152 <section>
|
|
153 <title>The Profiler</title>
|
|
154 <para>
|
|
155 </para>
|
|
156 </section>
|
|
157 </section>
|
|
158
|
|
159 <section>
|
|
160 <title>C Compiler Component Files and File Usage</title>
|
|
161 <para>
|
|
162 </para>
|
|
163
|
|
164 <section>
|
|
165 <title>Temporary Files</title>
|
|
166 <para>
|
|
167 </para>
|
|
168 </section>
|
|
169 </section>
|
|
170
|
|
171 <section>
|
|
172 <title>Running the Compiler</title>
|
|
173 <para>
|
|
174 </para>
|
|
175 </section>
|
|
176
|
472
|
177 <section>
|
|
178 <title>Compiler Option Flags</title>
|
|
179 <para>
|
|
180 The compiler recognizes several command-line option flags which
|
|
181 modify the compilation process where needed. All flags are
|
|
182 recognized before compilation commences so the flags may be placed
|
|
183 anywhere on the command line. Flags may be ran together as in "-ro",
|
|
184 except where a flag is followed by something else; see "-f=" and
|
|
185 "-d" for examples.
|
|
186 </para>
|
|
187 <para>
|
|
188 -A
|
|
189 suppresses assembly, leaving the output as assembler code in a
|
|
190 file whose name is postfixed ".a".
|
|
191 </para>
|
|
192 <para>
|
|
193 -E=<number>
|
|
194 Set the edition number constant byte to the number given. This is
|
|
195 an OS-9 convention for memory modules.
|
|
196 </para>
|
|
197 <para>
|
|
198 -O
|
|
199 inhibits the assembly code optimizer pass. The optimizer will
|
|
200 shorten object code by about 11% with a comparable increase in speed
|
|
201 and is recommended for production versions of de-bugged programs.
|
|
202 </para>
|
|
203 <para>
|
|
204 -P
|
|
205 invokes the profiler to generate function frequency
|
|
206 statistics after program execution.
|
|
207 </para>
|
|
208 <para>
|
|
209 -R
|
|
210 suppresses linking library modules into an executable program.
|
|
211 Outputs are left in files with postfixes ".r".
|
|
212 </para>
|
|
213 <para>
|
|
214 -M=<memory size>
|
|
215 will instruct the linker to allocate <memory size>
|
|
216 for data, stack, and parameter area. Memory size may be expressed
|
|
217 in pages (an integer) or in kilobytes by appending "k" to an
|
|
218 integer. For more details of the use of this option, see the
|
|
219 "Memory Management" section of this manual.
|
|
220 </para>
|
|
221 <para>
|
|
222 -L=<filename>
|
|
223 specifies a library to be searched by the linker
|
|
224 before the Standard Library and system interface.
|
|
225 </para>
|
|
226 <para>
|
|
227 -F=<path>
|
|
228 overrides the above output file naming. The output file
|
|
229 will be left with <filename> as its name. This flag does not make
|
|
230 sense in multiple source mode, and either the -a or -r flag is also
|
|
231 present. The module will be called the last name in <path>.
|
|
232 </para>
|
|
233 <para>
|
|
234 -C
|
|
235 will output the source code as comments with the assembler code.
|
|
236 </para>
|
|
237 <para>
|
|
238 -S
|
|
239 stops the generation of stack-checking code. -S should only be
|
|
240 used with great care when the appication is extremely time-critical
|
|
241 and when the use of the stack by compiler generated code is fully
|
|
242 understood.
|
|
243 </para>
|
|
244 <para>
|
|
245 -D<identifier>
|
|
246 is equivalent to "#define <identifier>" written in
|
|
247 the source file. -D is useful where different versions of a program
|
|
248 are maintained in one source file and differentiated by means of the
|
|
249 "#ifdef" of "#ifndef" pre-processor directives. If the <identifier>
|
|
250 is used as a macro for expansion by the pre-processor, "1"(one) will
|
|
251 be the expanded "value" unless the form "-d<identifier>=<string>" is
|
|
252 used in which case the expansion will be <string>.
|
|
253 </para>
|
|
254 <table frame="none">
|
|
255 <title>Command Line and Option Flag Examples</title>
|
|
256 <tgroup cols="3">
|
|
257 <colspec colwidth="1.5in" colname="c1">
|
|
258 <colspec colwidth="1.5in" colname="c2">
|
|
259 <colspec colwidth="1.5in" colname="c3">
|
|
260 <thead>
|
|
261 <row>
|
|
262 <entry>command line</entry>
|
|
263 <entry>action</entry>
|
|
264 <entry>output file(s)</entry>
|
|
265 </row>
|
|
266 </thead>
|
|
267 <tbody>
|
|
268 <row>
|
|
269 <entry>cc prg.c</entry>
|
|
270 <entry>compile to an executable program</entry>
|
|
271 <entry>prg</entry>
|
|
272 <entry></entry>
|
|
273 </row>
|
|
274 <row>
|
|
275 <entry>cc prg.c -a</entry>
|
|
276 <entry>compile to assembly language source code</entry>
|
|
277 <entry>prg.a</entry>
|
|
278 </row>
|
|
279 <row>
|
|
280 <entry>cc prg.c -r</entry>
|
|
281 <entry>compile to relocatable module</entry>
|
|
282 <entry>prg.r</entry>
|
|
283 </row>
|
|
284 <row>
|
|
285 <entry>cc prg1.c prg2.c prg3.c</entry>
|
|
286 <entry>compile to executable program</entry>
|
|
287 <entry>prg1.r, prg2.r, prg3.r, output</entry>
|
|
288 </row>
|
|
289 <row>
|
|
290 <entry>cc prg1.c prg2.a prg3.r</entry>
|
|
291 <entry>compile prg1.c, assemble prg2.a and combine all into
|
|
292 and executable program</entry>
|
|
293 <entry>prg1.r, prg2.r</entry>
|
|
294 </row>
|
|
295 <row>
|
|
296 <entry>cc prg1.c prg2.c -a</entry>
|
|
297 <entry>compile to assembly language source code</entry>
|
|
298 <entry>prg1.a, prg2.a</entry>
|
|
299 </row>
|
|
300 <row>
|
|
301 <entry>cc prg1.c prg2.c -f=prg</entry>
|
|
302 <entry>compile to executable program</entry>
|
|
303 <entry>prg</entry>
|
|
304 </row>
|
|
305 </tbody>
|
|
306 </tgroup>
|
|
307 </table>
|
|
308
|
466
|
309 </section>
|
|
310 </chapter>
|