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