2c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. .TH 2C 1
  2. .SH NAME
  3. 0c, 1c, 2c, 4c, 5c, 6c, 7c, 8c, 9c, kc, qc, vc, xc \- 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. Associated with each compiler is a string
  19. .IR objtype :
  20. .TP 1.5i
  21. .B "0c spim
  22. little-endian MIPS 4000 family
  23. .TP
  24. .B "1c 68000
  25. Motorola MC68000
  26. .TP
  27. .B "2c 68020
  28. Motorola MC68020
  29. .TP
  30. .B "4c mips2
  31. big-endian MIPS 4000 family
  32. .TP
  33. .B "5c arm
  34. ARM 7500
  35. .TP
  36. .B "6c 960
  37. Intel i960
  38. .TP
  39. .B "7c alpha
  40. Digital Alpha APX
  41. .TP
  42. .B "8c 386
  43. Intel i386, i486, Pentium, etc.
  44. .TP
  45. .B "9c 29000
  46. AMD 29000 family
  47. .TP
  48. .B "kc sparc
  49. Sun SPARC
  50. .TP
  51. .B "qc power
  52. Power PC,
  53. .TP
  54. .B "vc mips
  55. big-endian MIPS 3000 family
  56. .TP
  57. .B "xc 3210
  58. AT&T DSP 3210.
  59. .PP
  60. The compilers handle most preprocessing directives themselves; a complete
  61. preprocessor is available in
  62. .IR cpp (1),
  63. which must be run separately.
  64. .PP
  65. Let the first letter of the compiler name be
  66. .IR O =
  67. .BR 0 ,
  68. .BR 1 ,
  69. .BR 2 ,
  70. .BR 4 ,
  71. .BR 5 ,
  72. .BR 6 ,
  73. .BR 7 ,
  74. .BR 8 ,
  75. .BR 9 ,
  76. .BR k ,
  77. .BR q ,
  78. .BR v ,
  79. or
  80. .BR x .
  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. .TP 1i
  109. .BI -o " obj"
  110. Place output in file
  111. .I obj
  112. (allowed only if there is just one input file).
  113. Default is to take the last element of the input file name,
  114. strip any trailing
  115. .BR .c ,
  116. and append
  117. .RI . O .
  118. .TP
  119. .B -w
  120. Print warning messages about unused variables, etc.
  121. .TP
  122. .B -B
  123. Accept functions without a new-style
  124. ANSI C function prototype.
  125. By default, the compilers reject functions
  126. used without a defined prototype,
  127. although ANSI C permits them.
  128. .TP
  129. .BI -D\*S name=def
  130. .br
  131. .ns
  132. .TP
  133. .BI -D \*Sname
  134. Define the
  135. .I name
  136. to the preprocessor,
  137. as if by
  138. .LR #define .
  139. If no definition is given, the name is defined as
  140. .LR 1 .
  141. .TP
  142. .BI -F
  143. Enable type-checking of calls to
  144. .IR print (2)
  145. and other formatted print routines. See the discussion
  146. of extensions, below.
  147. .TP
  148. .BI -I \*Sdir
  149. An
  150. .L #include
  151. file whose name does not begin with
  152. slash
  153. or is enclosed in double quotes
  154. is always
  155. sought first in the directory
  156. of the
  157. .I file
  158. argument. If this fails, or the name is enclosed in
  159. .BR <> ,
  160. it is then sought
  161. in directories named in
  162. .B -I
  163. options,
  164. then in
  165. .BR /sys/include ,
  166. and finally in
  167. .BR /$objtype/include .
  168. .TP
  169. .B -N
  170. Suppress automatic registerization and optimization.
  171. .TP
  172. .B -S
  173. Print an assembly language version of the object code
  174. on standard output as well as generating the
  175. .RI . O
  176. file.
  177. .TP
  178. .B -V
  179. By default, the compilers are non-standardly lax about type equality between
  180. .B void*
  181. values and other pointers; this flag requires ANSI C conformance.
  182. .TP
  183. .B -p
  184. Invoke a standard ANSI C preprocessor before compiling.
  185. .TP
  186. .B -a
  187. Instead of compiling, print on standard output acid functions (see
  188. .IR acid (1))
  189. for examining structures declared in the source files.
  190. .TP
  191. .B -aa
  192. Like
  193. .B -a
  194. except suppress information about structures
  195. declared in included header files.
  196. .PP
  197. The compilers support several extensions to ANSI C:
  198. .TP
  199. \-
  200. A structure or union may contain unnamed substructures and subunions.
  201. The fields of the substructures or
  202. subunions can then be used as if they were members of the parent
  203. structure or union (the resolution of a name conflict is unspecified).
  204. When a pointer to the outer structure or union is used in a context
  205. that is only legal for the unnamed substructure, the compiler promotes
  206. the type and adjusts the pointer value to point at the substructure.
  207. If the unnamed structure or union is of a type with a tag name specified by a
  208. .B typedef
  209. statement,
  210. the unnamed structure or union can be explicitly referenced
  211. by <struct variable>.<tagname>.
  212. .TP
  213. \-
  214. A structure value can be formed with an expression such as
  215. .EX
  216. (struct S){v1, v2, v3}
  217. .EE
  218. where the list elements are values for the fields of struct
  219. .BR S .
  220. .TP
  221. \-
  222. Array initializers can specify the indices of the array in square
  223. brackets, as
  224. .EX
  225. int a[] = { [3] 1, [10] 5 };
  226. .EE
  227. which initializes the third and tenth elements of the eleven-element array
  228. .BR a .
  229. .TP
  230. \-
  231. Structure initializers can specify the structure element by using the name
  232. following a period, as
  233. .EX
  234. int struct { int x; int y; } s = { .y 1, .x 5 };
  235. .EE
  236. which initializes elements
  237. .B y
  238. and then
  239. .B x
  240. of the structure
  241. .BR s .
  242. These forms also accept the new ANSI C notation, which includes an equal sign:
  243. .EX
  244. int a[] = { [3] = 1, [10] = 5 };
  245. int struct { int x; int y; } s = { .y = 1, .x = 5 };
  246. .EE
  247. .TP
  248. \-
  249. A global variable can be dedicated to a register
  250. by declaring it
  251. .B "extern register"
  252. in
  253. .I all
  254. modules and libraries.
  255. .TP
  256. \-
  257. A
  258. .B #pragma
  259. of the form
  260. .EX
  261. #pragma lib "libbio.a"
  262. .EE
  263. records that the program needs to be loaded with file
  264. .BR /$objtype/lib/libbio.a ;
  265. such lines, typically placed in library header files, obviate the
  266. .B -l
  267. option of the loaders. To help identify files in non-standard directories,
  268. within the file names in the
  269. .B #pragmas
  270. the string
  271. .B $M
  272. represents the name of the architecture
  273. (e.g.,
  274. .BR mips )
  275. and
  276. .B $O
  277. represents its identifying character
  278. (e.g.,
  279. .BR v ).
  280. .TP
  281. \-
  282. A
  283. .B #pragma
  284. of the form
  285. .EX
  286. #pragma varargck argpos error 2
  287. .EE
  288. tells the compiler that the second argument to
  289. .B error
  290. is a
  291. .BR print -like
  292. format string (see
  293. .IR print (2))
  294. that identifies the handling of subsequent arguments.
  295. The
  296. .B #pragma
  297. .EX
  298. #pragma varargck type "s" char*
  299. .EE
  300. says that the format verb
  301. .B s
  302. processes an argument of type
  303. .BR char *.
  304. The
  305. .B #pragma
  306. .EX
  307. #pragma varargck flag 'c'
  308. .EE
  309. says that
  310. .B c
  311. is a flag character.
  312. These
  313. .B #pragmas
  314. are used, if the
  315. .B -F
  316. option is enabled, to type-check calls to
  317. .B print
  318. and other such routines.
  319. .TP
  320. \-
  321. The C++ comment
  322. .RB ( //
  323. to end of line)
  324. is accepted as well as the normal
  325. convention of
  326. .B /*
  327. .BR */ .
  328. .TP
  329. \-
  330. The compilers accept
  331. .B long
  332. .B long
  333. variables as a 64-bit type.
  334. The standard header typedefs this to
  335. .BR vlong .
  336. Arithmetic on
  337. .B vlong
  338. values is usually emulated by a run-time library.
  339. .SH EXAMPLE
  340. For the 68020, produce a program
  341. .B prog
  342. from C files
  343. .BR main.c
  344. and
  345. .BR sub.c :
  346. .IP
  347. .EX
  348. 2c -FVw main.c sub.c
  349. 2l -o prog main.2 sub.2
  350. .EE
  351. .SH FILES
  352. .TF /$objtype/include
  353. .TP
  354. .B /sys/include
  355. system area for machine-independent
  356. .B #include
  357. directives.
  358. .TP
  359. .B /$objtype/include
  360. system area for machine-dependent
  361. .B #include
  362. directives.
  363. .SH SOURCE
  364. .TF /sys/src/cmd/2c,\ etc.
  365. .TP
  366. .B /sys/src/cmd/cc
  367. machine-independent part
  368. .TP
  369. .BR /sys/src/cmd/2c ,\ etc.
  370. machine-dependent part
  371. .SH "SEE ALSO"
  372. .IR 2a (1),
  373. .IR 2l (1),
  374. .IR cpp (1),
  375. .IR mk (1),
  376. .IR nm (1),
  377. .IR pcc (1),
  378. .IR db (1),
  379. .IR acid (1),
  380. .PP
  381. Rob Pike,
  382. ``How to Use the Plan 9 C Compiler''
  383. .SH BUGS
  384. The i960 compiler has been used only to program one I/O controller
  385. and is certainly buggy.
  386. .PP
  387. The default preprocessor only handles
  388. .LR #define ,
  389. .LR #include ,
  390. .LR #undef ,
  391. .LR #ifdef ,
  392. .LR #line ,
  393. and
  394. .LR #ifndef .
  395. For a full ANSI preprocessor, use
  396. the
  397. .B p
  398. option.