2c 8.1 KB

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