2c 9.4 KB

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