]> git.lizzy.rs Git - plan9front.git/blob - sys/man/1/2c
Import sources from 2011-03-30 iso image - sys/man
[plan9front.git] / sys / man / 1 / 2c
1 .TH 2C 1
2 .SH NAME
3 0c, 1c, 2c, 5c, 6c, 7c, 8c, kc, qc, vc \- C compilers
4 .SH SYNOPSIS
5 .B 2c
6 [
7 .I option ...
8 ]
9 [
10 .I file ...
11 ]
12 .br
13 etc.
14 .SH DESCRIPTION
15 These commands compile the named C
16 .I files
17 into object files for the corresponding architecture.
18 If there are multiple C
19 .IR files ,
20 the compilers will attempt to keep
21 .B $NPROC
22 compilations running concurrently.
23 Associated with each compiler is a string
24 .IR objtype ,
25 for example
26 .TF "6c amd64 "
27 .PD
28 .TP
29 .B "0c spim
30 little-endian MIPS 3000 family
31 .TP
32 .B "1c 68000
33 Motorola MC68000
34 .TP
35 .B "2c 68020
36 Motorola MC68020
37 .TP
38 .B "5c arm
39 little-endian ARM
40 .TP
41 .B "6c amd64
42 AMD64 and compatibles (e.g., Intel EM64T)
43 .TP
44 .B "7c alpha
45 Digital Alpha APX
46 .TP
47 .B "8c 386
48 Intel i386, i486, Pentium, etc.
49 .TP
50 .B "kc sparc
51 Sun SPARC
52 .TP
53 .B "qc power
54 Power PC
55 .TP
56 .B "vc mips
57 big-endian MIPS 3000 family
58 .PP
59 The compilers handle most preprocessing directives themselves; a complete
60 preprocessor is available in
61 .IR cpp (1),
62 which must be run separately.
63 .PP
64 Let the first letter of the compiler name be
65 .IR O =
66 .BR 0 ,
67 .BR 1 ,
68 .BR 2 ,
69 .BR 5 ,
70 .BR 6 ,
71 .BR 7 ,
72 .BR 8 ,
73 .BR k ,
74 .BR q ,
75 or
76 .BR v .
77 The output object files end in
78 .RI . O .
79 The letter is also the prefix of related programs:
80 .IB O a
81 is the assembler,
82 .IB O l
83 is the loader.
84 Plan 9 conventionally sets the
85 .B $objtype
86 environment variable to the
87 .I objtype
88 string appropriate to the current machine's type.
89 Plan 9 also conventionally has
90 .RI / objtype
91 directories, which contain among other things:
92 .BR include ,
93 for machine-dependent include files;
94 .BR lib ,
95 for public object code libraries;
96 .BR bin ,
97 for public programs;
98 and
99 .BR mkfile ,
100 for preconditioning
101 .IR mk (1).
102 .PP
103 The compiler options are:
104 .TF Dname
105 .PD
106 .TP
107 .BI -o " obj"
108 Place output in file
109 .I obj
110 (allowed only if there is just one input file).
111 Default is to take the last element of the input file name,
112 strip any trailing
113 .BR .c ,
114 and append
115 .RI . O .
116 .TP
117 .B -w
118 Print warning messages about unused variables, etc.
119 .TP
120 .B -B
121 Accept functions without a new-style
122 ANSI C function prototype.
123 By default, the compilers reject functions
124 used without a defined prototype,
125 although ANSI C permits them.
126 .TP
127 .BI -D\*S name=def
128 .br
129 .ns
130 .TP
131 .BI -D \*Sname
132 Define the
133 .I name
134 to the preprocessor,
135 as if by
136 .LR #define .
137 If no definition is given, the name is defined as
138 .LR 1 .
139 .TP
140 .BI -F
141 Enable type-checking of calls to
142 .IR print (2)
143 and other formatted print routines.  See the discussion
144 of extensions, below.
145 .TP
146 .BI -I \*Sdir
147 An
148 .L #include
149 file whose name does not begin with
150 slash
151 or is enclosed in double quotes
152 is always
153 sought first in the directory
154 of the
155 .I file
156 argument.  If this fails,
157 the
158 .I -.
159 flag is given or the name is enclosed in
160 .BR <> ,
161 it is then sought
162 in directories named in
163 .B -I
164 options,
165 then in
166 .BR /sys/include ,
167 and finally in
168 .BR /$objtype/include .
169 .TP
170 .B -.
171 Suppress the automatic searching for include files in
172 the directory of the file argument.
173 .TP
174 .B -N
175 Suppress automatic registerization and optimization.
176 .TP
177 .B -S
178 Print an assembly language version of the object code
179 on standard output as well as generating the
180 .RI . O
181 file.
182 .TP
183 .B -T
184 Pass type signatures on all external and global entities.
185 The signature is based on the C
186 .B signof
187 operator.
188 See
189 .IR dynld (2).
190 .TP
191 .B -V
192 By default, the compilers are non-standardly lax about type equality between
193 .B void*
194 values and other pointers; this flag requires ANSI C conformance.
195 .TP
196 .B -p
197 Invoke a standard ANSI C preprocessor before compiling.
198 .TP
199 .B -a
200 Instead of compiling, print on standard output acid functions (see
201 .IR acid (1))
202 for examining structures declared in the source files.
203 .TP
204 .B -aa
205 Like
206 .B -a
207 except suppress information about structures
208 declared in included header files.
209 .TP
210 .B -n
211 When used with
212 .B -a
213 or
214 .BR -aa ,
215 places acid functions in
216 .IB file .acid
217 for input
218 .IB file .c ,
219 and not on standard output.
220 .PP
221 The compilers support several extensions to ANSI C:
222 .TF \|
223 .PD
224 .TP
225 \-
226 A structure or union may contain unnamed substructures and subunions.
227 The fields of the substructures or
228 subunions can then be used as if they were members of the parent
229 structure or union (the resolution of a name conflict is unspecified).
230 When a pointer to the outer structure or union is used in a context
231 that is only legal for the unnamed substructure, the compiler promotes
232 the type and adjusts the pointer value to point at the substructure.
233 If the unnamed structure or union is of a type with a tag name specified by a
234 .B typedef
235 statement,
236 the unnamed structure or union can be explicitly referenced
237 by <struct variable>.<tagname>.
238 .TP
239 \-
240 A structure value can be formed with an expression such as
241 .EX
242     (struct S){v1, v2, v3}
243 .EE
244 where the list elements are values for the fields of struct
245 .BR S .
246 .TP
247 \-
248 Array initializers can specify the indices of the array in square
249 brackets, as
250 .EX
251     int a[] = { [3] 1, [10] 5 };
252 .EE
253 which initializes the third and tenth elements of the eleven-element array
254 .BR a .
255 .TP
256 \-
257 Structure initializers can specify the structure element by using the name
258 following a period, as
259 .EX
260     struct { int x; int y; } s = { .y 1, .x 5 };
261 .EE
262 which initializes elements
263 .B y
264 and then
265 .B x
266 of the structure
267 .BR s .
268 These forms also accept the new ANSI C notation, which includes an equal sign:
269 .EX
270     int a[] = { [3] = 1, [10] = 5 };
271     struct { int x; int y; } s = { .y = 1, .x = 5 };
272 .EE
273 .TP
274 \-
275 A global variable can be dedicated to a register
276 by declaring it
277 .B "extern register"
278 in
279 .I all
280 modules and libraries.
281 .TP
282 \-
283 A
284 .B #pragma
285 of the form
286 .EX
287     #pragma lib "libbio.a"
288 .EE
289 records that the program needs to be loaded with file
290 .BR /$objtype/lib/libbio.a ;
291 such lines, typically placed in library header files, obviate the
292 .B -l
293 option of the loaders.  To help identify files in non-standard directories,
294 within the file names in the
295 .B #pragmas
296 the string
297 .B $M
298 represents the name of the architecture
299 (e.g.,
300 .BR mips )
301 and
302 .B $O
303 represents its identifying character
304 (e.g.,
305 .BR v ).
306 .TP
307 \-
308 A
309 .B #pragma
310 of the form
311 .EX
312     #pragma varargck argpos error 2
313 .EE
314 tells the compiler that the second argument to
315 .B error
316 is a
317 .BR print -like
318 format string (see
319 .IR print (2))
320 that identifies the handling of subsequent arguments.
321 The
322 .B #pragma
323 .EX
324     #pragma varargck type "s" char*
325 .EE
326 says that the format verb
327 .B s
328 processes an argument of type
329 .BR char *.
330 The
331 .B #pragma
332 .EX
333     #pragma varargck flag 'c'
334 .EE
335 says that
336 .B c
337 is a flag character.
338 These
339 .B #pragmas
340 are used, if the
341 .B -F
342 option is enabled, to type-check calls to
343 .B print
344 and other such routines.
345 .TP
346 \-
347 A
348 .B #pragma
349 with any of the following forms:
350 .EX
351     #pragma incomplete \fItype\fP
352     #pragma incomplete struct \fItag\fP
353     #pragma incomplete union \fItag\fP
354 .EE
355 where
356 .I type
357 is a
358 .BR typedef 'd
359 name for a structure or union type, and
360 .I tag
361 is a structure or union tag,
362 tells the compiler that
363 the corresponding type
364 should have its signature calculated as an incomplete type
365 even if it is subsequently fully defined.
366 This allows the type signature mechanism to work in the presence
367 of opaque types declared in header files, with their full definitions
368 visible only to the code which manipulates them.
369 With some imported software it might be necessary to turn off the
370 signature generation completely for a large body of code (typically
371 at the start and end of a particular include file).
372 If
373 .I type
374 is the word
375 .BR _off_ ,
376 signature generation is turned off; if
377 .I type
378 is the word
379 .BR _on_ ,
380 the compiler will generate signatures.
381 .TP
382 \-
383 The C++ comment
384 .RB ( //
385 to end of line)
386 is accepted as well as the normal
387 convention of
388 .B /*
389 .BR */ .
390 .TP
391 \-
392 The compilers accept
393 .B long
394 .B long
395 variables as a 64-bit type.
396 The standard header typedefs this to
397 .BR vlong .
398 Arithmetic on
399 .B  vlong
400 values is usually emulated by a run-time library,
401 though in at least
402 .IR 8c ,
403 only division and modulus use the run-time library
404 and the other operators generate in-line code
405 (and
406 .I uvlong-expression
407 .I divison-or-modulus
408 .BI "(1<<" constant )
409 will turn into in-line bit operations,
410 as is done for shorter
411 .I unsigned
412 expressions).
413 .SH EXAMPLE
414 For the 68020, produce a program
415 .B prog
416 from C files
417 .BR main.c
418 and
419 .BR sub.c :
420 .IP
421 .EX
422 2c -FVw main.c sub.c
423 2l -o prog main.2 sub.2
424 .EE
425 .SH FILES
426 .TF /$objtype/include
427 .TP
428 .B /sys/include
429 system area for machine-independent
430 .B #include
431 directives.
432 .TP
433 .B /$objtype/include
434 system area for machine-dependent
435 .B #include
436 directives.
437 .SH SOURCE
438 .TF /sys/src/cmd/2c,\ etc.
439 .TP
440 .B /sys/src/cmd/cc
441 machine-independent part
442 .TP
443 .BR /sys/src/cmd/2c ,\ etc.
444 machine-dependent part
445 .SH "SEE ALSO"
446 .IR 2a (1),
447 .IR 2l (1),
448 .IR cpp (1),
449 .IR mk (1),
450 .IR nm (1),
451 .IR pcc (1),
452 .IR db (1),
453 .IR acid (1)
454 .\" .IR ansitize (1)
455 .PP
456 Rob Pike,
457 ``How to Use the Plan 9 C Compiler''
458 .SH BUGS
459 The list of compilers given above is only partial,
460 not all architectures are supported on all systems,
461 some have been retired and some
462 are provided by third parties.
463 .PP
464 The default preprocessor only handles
465 .LR #define ,
466 .LR #include ,
467 .LR #undef ,
468 .LR #ifdef ,
469 .LR #line ,
470 and
471 .LR #ifndef .
472 For a full ANSI preprocessor, use
473 the
474 .B p
475 option.
476 .PP
477 The default search order for include files
478 differs to that of
479 .IR cpp (1).
480 .PP
481 Some features of C99, the 1999 ANSI C standard,
482 are implemented.
483 .PP
484 .B switch
485 expressions may not be either signedness of
486 .B vlong
487 on 32-bit architectures
488 .RI ( 8c
489 at least).
490 .PP
491 The implementation of
492 .B vlong
493 assignment can use a static location
494 and this can be disturbed by interrupts
495 (e.g., notes)
496 .RI ( 8c
497 at least).