8c 9.4 KB

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