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