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>
|
617
|
92 K & R frequently refer to characteristics of the C language
|
|
93 whose exact operations depend on the architacture and instruction
|
|
94 set of the computer actually used. This section contains specific
|
|
95 information regarding this version of C for the 6809 processor.
|
530
|
96 </para>
|
|
97
|
|
98 <section>
|
|
99 <title>Data Representation and Storage Requirements</title>
|
|
100 <para>
|
|
101 </para>
|
|
102 </section>
|
|
103
|
|
104 <section>
|
|
105 <title>Register Variables</title>
|
|
106 <para>
|
|
107 </para>
|
|
108 </section>
|
|
109
|
|
110 <section>
|
|
111 <title>Access To Command Line Parameters</title>
|
|
112 <para>
|
609
|
113 The standard C arguments "argc" and "argv" are available to
|
|
114 "main" as described in K & R page 110. The start-up routine for C
|
|
115 programs ensures that the parameter string passed to it by the
|
|
116 parent process is converted into null-terminated strings as expected
|
|
117 by the program. In addition, it will run together as a single
|
|
118 argument any strings enclosed between single or double quotes ("'" or '"').
|
|
119 If either is part of the string required, then the other
|
|
120 should be used as a delimiter.
|
530
|
121 </para>
|
|
122 </section>
|
|
123 </section>
|
|
124
|
|
125 <section>
|
|
126 <title>System Calls and the Standard Library</title>
|
|
127
|
|
128 <section>
|
|
129 <title>Operating System Calls</title>
|
|
130 <para>
|
|
131 </para>
|
|
132 </section>
|
|
133
|
|
134 <section>
|
|
135 <title>The Standard Library</title>
|
|
136 <para>
|
|
137 </para>
|
|
138 </section>
|
|
139 </section>
|
|
140
|
|
141 <section>
|
|
142 <title>Run-time Arithmetic Error Handling</title>
|
|
143 <para>
|
|
144 </para>
|
|
145 </section>
|
|
146
|
|
147 <section>
|
|
148 <title>Achieving Maximum Program Performance</title>
|
|
149
|
|
150 <section>
|
|
151 <title>Programming Considerations</title>
|
|
152 <para>
|
617
|
153 Because the 6809 is an 8/16 bit microprocessor, the compiler
|
|
154 can generate efficient code for 8 and 16 bit objects (CHARs, INTs,
|
|
155 etc.). However, code for 32 and 64 bit values (LONGs, FLOATs,
|
|
156 DOUBLEs) can be at least four times longer and slower. Therefore
|
|
157 don't use LONG, FLOAT, or DOUBLE where INT or UNSIGNED will do.
|
|
158 </para>
|
|
159 <para>
|
|
160 The compiler can perform extensive evaluation of constant
|
|
161 expressions provided they involve only constants of type CHAR, INT,
|
|
162 and UNSIGNED. There is no constant expression evaluation at
|
|
163 compile-time (except single constants and "casts" of them) where
|
|
164 there are constants of type LONG, FLOAT, or DOUBLE, therefore,
|
|
165 complex constant expressions involving these types are evaluated at
|
|
166 run time by the compiled program. You should manually compute the
|
|
167 value of constant expressions of these types if speed is essential.
|
530
|
168 </para>
|
|
169 </section>
|
|
170
|
|
171 <section>
|
|
172 <title>The Optimizer Pass</title>
|
|
173 <para>
|
|
174 </para>
|
|
175 </section>
|
|
176
|
|
177 <section>
|
|
178 <title>The Profiler</title>
|
|
179 <para>
|
|
180 </para>
|
|
181 </section>
|
|
182 </section>
|
|
183
|
|
184 <section>
|
|
185 <title>C Compiler Component Files and File Usage</title>
|
|
186 <para>
|
|
187 </para>
|
|
188
|
|
189 <section>
|
|
190 <title>Temporary Files</title>
|
|
191 <para>
|
|
192 </para>
|
|
193 </section>
|
|
194 </section>
|
|
195
|
|
196 <section>
|
|
197 <title>Running the Compiler</title>
|
|
198 <para>
|
|
199 </para>
|
|
200 </section>
|
|
201
|
472
|
202 <section>
|
|
203 <title>Compiler Option Flags</title>
|
|
204 <para>
|
|
205 The compiler recognizes several command-line option flags which
|
|
206 modify the compilation process where needed. All flags are
|
|
207 recognized before compilation commences so the flags may be placed
|
|
208 anywhere on the command line. Flags may be ran together as in "-ro",
|
|
209 except where a flag is followed by something else; see "-f=" and
|
|
210 "-d" for examples.
|
|
211 </para>
|
|
212 <para>
|
|
213 -A
|
|
214 suppresses assembly, leaving the output as assembler code in a
|
|
215 file whose name is postfixed ".a".
|
|
216 </para>
|
|
217 <para>
|
|
218 -E=<number>
|
|
219 Set the edition number constant byte to the number given. This is
|
|
220 an OS-9 convention for memory modules.
|
|
221 </para>
|
|
222 <para>
|
|
223 -O
|
|
224 inhibits the assembly code optimizer pass. The optimizer will
|
|
225 shorten object code by about 11% with a comparable increase in speed
|
|
226 and is recommended for production versions of de-bugged programs.
|
|
227 </para>
|
|
228 <para>
|
|
229 -P
|
|
230 invokes the profiler to generate function frequency
|
|
231 statistics after program execution.
|
|
232 </para>
|
|
233 <para>
|
|
234 -R
|
|
235 suppresses linking library modules into an executable program.
|
|
236 Outputs are left in files with postfixes ".r".
|
|
237 </para>
|
|
238 <para>
|
|
239 -M=<memory size>
|
|
240 will instruct the linker to allocate <memory size>
|
|
241 for data, stack, and parameter area. Memory size may be expressed
|
|
242 in pages (an integer) or in kilobytes by appending "k" to an
|
|
243 integer. For more details of the use of this option, see the
|
|
244 "Memory Management" section of this manual.
|
|
245 </para>
|
|
246 <para>
|
|
247 -L=<filename>
|
|
248 specifies a library to be searched by the linker
|
|
249 before the Standard Library and system interface.
|
|
250 </para>
|
|
251 <para>
|
|
252 -F=<path>
|
|
253 overrides the above output file naming. The output file
|
|
254 will be left with <filename> as its name. This flag does not make
|
|
255 sense in multiple source mode, and either the -a or -r flag is also
|
|
256 present. The module will be called the last name in <path>.
|
|
257 </para>
|
|
258 <para>
|
|
259 -C
|
|
260 will output the source code as comments with the assembler code.
|
|
261 </para>
|
|
262 <para>
|
|
263 -S
|
|
264 stops the generation of stack-checking code. -S should only be
|
|
265 used with great care when the appication is extremely time-critical
|
|
266 and when the use of the stack by compiler generated code is fully
|
|
267 understood.
|
|
268 </para>
|
|
269 <para>
|
|
270 -D<identifier>
|
|
271 is equivalent to "#define <identifier>" written in
|
|
272 the source file. -D is useful where different versions of a program
|
|
273 are maintained in one source file and differentiated by means of the
|
|
274 "#ifdef" of "#ifndef" pre-processor directives. If the <identifier>
|
|
275 is used as a macro for expansion by the pre-processor, "1"(one) will
|
|
276 be the expanded "value" unless the form "-d<identifier>=<string>" is
|
|
277 used in which case the expansion will be <string>.
|
|
278 </para>
|
|
279 <table frame="none">
|
|
280 <title>Command Line and Option Flag Examples</title>
|
|
281 <tgroup cols="3">
|
|
282 <colspec colwidth="1.5in" colname="c1">
|
|
283 <colspec colwidth="1.5in" colname="c2">
|
|
284 <colspec colwidth="1.5in" colname="c3">
|
|
285 <thead>
|
|
286 <row>
|
|
287 <entry>command line</entry>
|
|
288 <entry>action</entry>
|
|
289 <entry>output file(s)</entry>
|
|
290 </row>
|
|
291 </thead>
|
|
292 <tbody>
|
|
293 <row>
|
|
294 <entry>cc prg.c</entry>
|
|
295 <entry>compile to an executable program</entry>
|
|
296 <entry>prg</entry>
|
|
297 <entry></entry>
|
|
298 </row>
|
|
299 <row>
|
|
300 <entry>cc prg.c -a</entry>
|
|
301 <entry>compile to assembly language source code</entry>
|
|
302 <entry>prg.a</entry>
|
|
303 </row>
|
|
304 <row>
|
|
305 <entry>cc prg.c -r</entry>
|
|
306 <entry>compile to relocatable module</entry>
|
|
307 <entry>prg.r</entry>
|
|
308 </row>
|
|
309 <row>
|
|
310 <entry>cc prg1.c prg2.c prg3.c</entry>
|
|
311 <entry>compile to executable program</entry>
|
|
312 <entry>prg1.r, prg2.r, prg3.r, output</entry>
|
|
313 </row>
|
|
314 <row>
|
|
315 <entry>cc prg1.c prg2.a prg3.r</entry>
|
|
316 <entry>compile prg1.c, assemble prg2.a and combine all into
|
|
317 and executable program</entry>
|
|
318 <entry>prg1.r, prg2.r</entry>
|
|
319 </row>
|
|
320 <row>
|
|
321 <entry>cc prg1.c prg2.c -a</entry>
|
|
322 <entry>compile to assembly language source code</entry>
|
|
323 <entry>prg1.a, prg2.a</entry>
|
|
324 </row>
|
|
325 <row>
|
|
326 <entry>cc prg1.c prg2.c -f=prg</entry>
|
|
327 <entry>compile to executable program</entry>
|
|
328 <entry>prg</entry>
|
|
329 </row>
|
|
330 </tbody>
|
|
331 </tgroup>
|
|
332 </table>
|
|
333
|
466
|
334 </section>
|
|
335 </chapter>
|