2c 7.0 KB

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