home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / c / ca < prev   
Encoding:
Text File  |  1975-06-26  |  10.8 KB  |  562 lines

  1. .pn 26
  2. .fp 3 G
  3. 'tr ^\|
  4. 'hc $
  5. 'tr @
  6. 'll 6.5i
  7. 'ps 10
  8. .ds op \s6\d\fIopt\fP\u\s10
  9. .ds * \fR\v'.2'*\fP\v'-.2'
  10. .ds ~ \v'.5'\s14~\s10\v'-.5'
  11. 'vs 11p
  12. .de pg
  13. .sp .4
  14. .ti 1
  15. ..
  16. .de et
  17. .sp .2
  18. .ft R
  19. .ti 1
  20. ..
  21. .de dp
  22. .sp .7
  23. .ne \\$1
  24. .ft I
  25. .nf
  26. ..
  27. .de ed
  28. .fi
  29. .br
  30. .ft R
  31. ..
  32. .de ul
  33. .sp 1.5
  34. .ne 4
  35. .ft G
  36. ..
  37. .de ms
  38. .sp  1
  39. .ne 4
  40. ..
  41. .de fo
  42. 'bp
  43. ..
  44. .de he
  45. .po 0
  46. .tl '-'''
  47. .po
  48. 'sp 0.5i
  49. .ft I
  50. .if o .tl '''C  Reference  Manual - %'
  51. .if e .tl 'C  Reference  Manual - %'''
  52. .ft
  53. 'sp 0.4i
  54. ..
  55. .de bG
  56. .br
  57. .fp 3 G
  58. .ft G
  59. ..
  60. .de eG
  61. .br
  62. .ft R
  63. ..
  64. .de it
  65. .ft I
  66. \\$1
  67. .ft R
  68. ..
  69. .de bd
  70. .ft G
  71. \\$1
  72. .ft R
  73. ..
  74. .de se
  75. .br
  76. .ft I
  77. ..
  78. .wh 0 he
  79. .wh -1i fo
  80. .sp 2
  81. .ce
  82. REFERENCES
  83. .sp 1.5
  84. .ta 2
  85. .tc @
  86. .in 2
  87. .ti 0
  88. 1.    Johnson, S. C., and Kernighan, B. W.
  89. ``The Programming Language B.'' Comp. Sci. Tech. Rep. #8., Bell Laboratories,
  90. 1972.
  91. .sp .6
  92. .ti 0
  93. 2.    Ritchie, D. M., and Thompson, K. L.
  94. ``The \s8UNIX\s10 Time-sharing System.''
  95. C. ACM \fG7, \fR17, July, 1974, pp. 365-375.
  96. .sp .6
  97. .ti 0
  98. 3.    Peterson, T. G., and Lesk, M. E.
  99. ``A User's Guide to the C Language on the IBM 370.''
  100. Internal Memorandum, Bell Laboratories, 1974.
  101. .sp .6
  102. .ti 0
  103. 4.    Thompson, K. L., and Ritchie, D. M.
  104. .ft I
  105. \s8UNIX\s10 Programmer's Manual.
  106. .ft R
  107. Bell Laboratories, 1973.
  108. .sp .7
  109. .ti 0
  110. 5.    Lesk, M. E., and Barres, B. A.
  111. ``The \s8GCOS\s10 C Library.''
  112. Internal memorandum, Bell Laboratories,
  113. 1974.
  114. .sp .7
  115. .to 0
  116. .ti 0
  117. 6.    Kernighan, B. W.  ``Programming in C\(mi A Tutorial.''
  118. Unpublished internal memorandum,
  119. Bell Laboratories, 1974.
  120. .in 0
  121. .bp
  122. .sp 1.5
  123. .ce 2
  124. APPENDIX 1
  125. .sp .3
  126. Syntax Summary
  127. .sp 1.5
  128. .ta .5i 1i 1.5i 2i 2.5i
  129. .in 3
  130. 1.  Expressions.
  131. .sp 1
  132. .dp 4
  133.     expression:
  134.         primary
  135.         \**\fI expression
  136.         \fG&\fI expression
  137.         \fG\(mi\fI expression
  138.         \fG!\fI expression
  139.         \*~ expression
  140.         \fR++\fI lvalue
  141.         \fR\(mi\(mi\fI lvalue
  142.         lvalue \fR++\fI
  143.         lvalue \fR\(mi\(mi\fI
  144.         \fGsizeof \fIexpression
  145.         expression binop expression
  146.         expression \fG?\fI expression \fG:\fI expression
  147.         lvalue asgnop expression
  148.         expression \fG,\fI expression
  149. .ed
  150. .dp 6
  151.     primary:
  152.         identifier
  153.         constant
  154.         string
  155.         \fG( \fIexpression \fG)\fI
  156.         \fIprimary \fG( \fIexpression-list\*(op \fG)\fI
  157.         primary \fG[\fI expression \fG]\fI
  158.         lvalue \fG. \fIidentifier
  159.         primary \fG\(em> \fIidentifier
  160. .ed
  161. .dp 2
  162.     lvalue:
  163.         identifier
  164.         primary \fG[ \fIexpression \fG]\fI
  165.         lvalue \fG. \fIidentifier
  166.         primary \fG\(em>\fI identifier
  167.         \** \fI expression
  168.         \fG(  \fIlvalue  \fG)\fR
  169. .ed
  170. .fi
  171. .sp .7
  172. The primary-expression operators
  173. .dp
  174. .ft G
  175.     (^)  [^]  .  \(em>
  176. .sp .5
  177. .ed
  178. have highest priority and group left-to-right.
  179. The unary operators
  180. .dp
  181. .ft G
  182.     \*  &  \(mi  !  \*~  \fR++  \(mi\(mi  \fGsizeof
  183. .ed
  184. .sp .5
  185. have priority below the primary operators
  186. but higher than any binary operator,
  187. and group right-to-left.
  188. Binary operators and the conditional operator
  189. all group left-to-right, and have priority
  190. decreasing
  191. as indicated:
  192. .dp
  193. .ft I
  194.     binop:
  195. .ft G
  196.         \**    /    %
  197.         +    \(mi
  198.         >>    <<
  199.         <    >    <=    >=
  200.         ==    !=
  201.         &
  202. .tr ^^
  203.         ^
  204. .tr ^\|
  205.         \(or
  206.         &&
  207.         \(or\(or
  208.         ?  :
  209. .tr ^^
  210. .sp .4
  211. .fi
  212. .ft R
  213. Assignment operators all have the same
  214. priority, and all group right-to-left.
  215. .dp 3
  216. .ft I
  217.     asgnop:
  218. .ft G
  219.         =  =+  =\(mi  =\**  =/  =%  =>>  =<<  =&  =^  =\(or
  220. .ed
  221. .tr ^\|
  222. .sp .4
  223. .ft R
  224. The comma operator has the lowest priority, and groups left-to-right.
  225. .sp .7
  226. 2.  Declarations.
  227. .dp 2
  228.     declaration:
  229.         decl-specifiers declarator-list\*(op  \fG;
  230. .ed
  231. .dp 5
  232.     decl-specifiers:
  233.         type-specifier
  234.         sc-specifier
  235.         type-specifier sc-specifier
  236.         sc-specifier type-specifier
  237. .ed
  238. .dp 4
  239.     sc-specifier:
  240. .ft G
  241.         auto
  242.         static
  243.         extern
  244.         register
  245. .ed
  246. .dp 6
  247.     type-specifier:
  248.         \fGint
  249.         \fGchar
  250.         \fGfloat
  251.         \fGdouble
  252.         struct { \fItype-decl-list }\fG
  253.         struct \fIidentifier { type-decl-list }\fG
  254.         struct \fIidentifier\fG
  255. .ed
  256. .dp 2
  257.     declarator-list:
  258.         declarator
  259.         declarator \fG,\fI declarator-list
  260. .ed
  261. .dp 6
  262.     declarator:
  263.         identifier
  264.         \** \fIdeclarator
  265.         declarator \fG( )\fI
  266.         declarator \fG[\fI constant-expression\*(op \fG]\fI
  267.         \fG( \fIdeclarator \fG)
  268. .ed
  269. .dp 2
  270.     type-decl-list:
  271.         type-declaration
  272.         type-declaration type-decl-list
  273. .ed
  274. .dp 2
  275.     type-declaration:
  276.         type-specifier declarator-list  \fG;
  277. .ed
  278. .sp 1.5
  279. 3. Statements.
  280. .dp 1
  281.     statement:
  282.         expression \fG;
  283. .se
  284.         { \fIstatement-list }
  285. .se
  286.         \fGif ( \fIexpression \fG) \fIstatement
  287. .se
  288.         \fGif ( \fI expression \fG) \fIstatement \fGelse \fIstatement
  289. .se
  290.         \fGwhile ( \fIexpression \fG) \fIstatement
  291. .se
  292.         \fGfor ( \fIexpression\*(op \fG; \fIexpression\*(op \fG; \fIexpression\*(op \fG) statement
  293. .se
  294.         \fGswitch ( \fIexpression \fG) \fIstatement
  295. .se
  296.         \fGcase \fIconstant-expression \fG:\fI statement
  297. .se
  298.         \fGdefault : \fIstatement
  299. .se
  300.         \fGbreak ;
  301. .se
  302.         \fGcontinue ;
  303. .se
  304. .ft G
  305.         return ;
  306. .se
  307. .ft G
  308.         return ( \fIexpression \fG) ;
  309. .se
  310. .ft G
  311.         goto \fIexpression \fG;
  312. .se
  313.         \fIidentifier \fG: \fIstatement
  314. .se
  315.         \fG;
  316. .ed
  317. .dp 2
  318.     statement-list:
  319.         statement
  320.         statement statement-list
  321. .sp 1.5
  322. .ft R
  323. 4.  External definitions.
  324. .dp 2
  325.     program:
  326.         external-definition
  327.         external-definition program
  328. .dp 2
  329.     external-definition:
  330.         function-definition
  331.         data-definition
  332. .ed
  333. .dp 2
  334.     function-definition:
  335.         type-specifier\*(op \fIfunction-declarator function-body
  336. .ed
  337. .dp 2
  338.     function-declarator:
  339.         declarator \fG( \fI parameter-list\*(op \fG)
  340. .ed
  341. .dp 1
  342.     parameter-list:
  343.         identifier
  344.         identifier \fG,\fI parameter-list
  345. .ed
  346. .dp 1
  347.     function-body:
  348.         type-decl-list function-statement
  349. .ed
  350. .dp 2
  351.     function-statement:
  352.         { declaration-list\*(op statement-list }
  353. .ed
  354. .dp 2
  355.     data-definition:
  356.         \fGextern\fI\*(op type-specifier\*(op init-declarator-list\*(op \fG;
  357. .ed
  358. .dp 2
  359.     init-declarator-list:
  360.         init-declarator
  361.         init-declarator \fG,\fI init-declarator-list
  362. .ed
  363. .dp 2
  364.     init-declarator:
  365.         declarator initializer\*(op
  366. .ed
  367. .dp 5
  368.     initializer:
  369.         constant
  370.         { constant-expression-list }
  371. .ed
  372. .dp 5
  373.     constant-expression-list:
  374.         constant-expression
  375.         constant-expression \fG,\fI constant-expression-list
  376. .ed
  377. .dp 2
  378.     constant-expression:
  379.         expression
  380. .ed
  381. .sp .4
  382. 5.  Preprocessor
  383. .dp 1
  384.     \fG# define \fIidentifier token-string
  385. .ed
  386. .dp 1
  387.     \fG# include "\fIfilename^\fG"
  388. .ed
  389. .in 0
  390. .bp
  391. .ds s \\s8
  392. .ds n \\s10
  393. .ft R
  394. .fi
  395. .sp 1
  396. .ce 2
  397. APPENDIX 2
  398. Implementation Peculiarities
  399. .sp 2
  400. This Appendix briefly summarizes the differences between the implementations
  401. of C on the \*sPDP\*n-11 under \*sUNIX\*n and on the
  402. \*sHIS\*n 6070 under \*sGCOS\*n;
  403. it includes some known bugs
  404. in each implementation.
  405. Each entry is keyed by an indicator as follows:
  406. .sp
  407. .ta .4i .8i
  408. .nf
  409.     h    hard to fix
  410.     g    \*sGCOS\*n version should probably be changed
  411.     u    \*sUNIX\*n version should probably be changed
  412.     d    Inherent difference likely to remain
  413. .sp
  414. .fi
  415. This list was prepared by M. E. Lesk, S. C. Johnson,
  416. E. N. Pinson, and the author.
  417. .sp 2
  418. .fi
  419. .ta .4i 1.2i
  420. .in 1.2i
  421. .ti0
  422. .ft I
  423. A. Bugs or differences from C language specifications
  424. .ft R
  425. .sp
  426. .ti0
  427. hg    A.1)    \*sGCOS\*n does not do type conversions in ``?:''.
  428. .ti0
  429. hg    A.2)    \*sGCOS\*n has a bug in \fGint\fR and \fGreal\fR comparisons; the numbers
  430. are compared by subtraction, and the difference must not overflow.
  431. .ti 0
  432. g    A.3)    When \fIx\fR is a \fGfloat\fR, the construction ``test ? \(mix : x''
  433. is illegal on \*sGCOS\*n.
  434. .ti0
  435. hg    A.4)    ``p1\(mi>p2 =+ 2'' causes a compiler error, where p1 and p2 are pointers.
  436. .ti0
  437. u    A.5)    On \*sUNIX\*n, the expression in a \fGreturn\fR statement is \fInot\fR
  438. converted to the type of the function, as promised.
  439. .ti0
  440. hug    A.6)    \fGentry\fR statement is not implemented at all.
  441. .sp
  442. .ne 5
  443. .ft I
  444. .ti0
  445. .ft I
  446. B. Implementation differences
  447. .ft R
  448. .sp
  449. .ti0
  450. d    B.1)    Sizes of character constants differ; \*sUNIX\*n: 2, \*sGCOS\*n: 4.
  451. .ti0
  452. d    B.2)    Table sizes in compilers differ.
  453. .ti0
  454. d    B.3)    \fGchar\fRs and \fGint\fRs have different sizes;
  455. \fGchar\fRs are 8 bits on \*sUNIX\*n, 9 on \*sGCOS\*n; words are 16 bits
  456. on \*sUNIX\*n and 36 on \*sGCOS\*n.
  457. There are corresponding differences in representations of
  458. \fGfloat\fRs and \fGdouble\fRs.
  459. .ti0
  460. d    B.4)    Character arrays stored left to right in a word
  461. in \*sGCOS\*n, right to left in \*sUNIX\*n.
  462. .ti0
  463. g    B.5)    Passing of floats and doubles differs;
  464. \*sUNIX\*n passes on stack, \*sGCOS\*n passes pointer (hidden to normal user).
  465. .ti0
  466. g    B.6)    Structures and strings are aligned on a word
  467. boundary in \*sUNIX\*n, not aligned in \*sGCOS\*n.
  468. .ti0
  469. g    B.7)    \*sGCOS\*n preprocessor supports #rename, #escape;
  470. \*sUNIX\*n has only #define, #include.
  471. .ti0
  472. u    B.8)    Preprocessor is not invoked on \*sUNIX\*n unless first
  473. character of file is ``#''.
  474. .ti0
  475. u    B.9)    The external definition ``static int .^.^.''
  476. is legal on \*sGCOS\*n, but gets a diagnostic on \*sUNIX\*n.
  477. (On \*sGCOS\*n it means an identifier global to the
  478. routines in the file but invisible to routines
  479. compiled separately.)
  480. .ti 0
  481. g    B.10)    A compound statement on \*sGCOS\*n must contain one ``;''
  482. but on \*sUNIX\*n may be empty.
  483. .ti 0
  484. g    B.11)    On \*sGCOS\*n case distinctions in identifiers and keywords are
  485. ignored; on \*sUNIX\*n case is significant everywhere,
  486. with keywords in lower case.
  487. .sp
  488. .ne 5
  489. .ti0
  490. .ft I
  491. C. Syntax Differences
  492. .ft R
  493. .sp
  494. .ti0
  495. g    C.1)    \*sUNIX\*n allows broader classes of initialization;
  496. on \*sGCOS\*n an initializer must be a constant, name, or string.
  497. Similarly,
  498. \*sGCOS\*n is much stickier about wanting braces
  499. around initializers and in particular they must be present
  500. for array initialization.
  501. .ti0
  502. g    C.2)    ``int extern'' illegal on \*sGCOS\*n; must have ``extern int''
  503. (storage class before type).
  504. .ti0
  505. g    C.3)    Externals on \*sGCOS\*n must have a type (not defaulted
  506. to \fGint\fR).
  507. .ti0
  508. u    C.4)    \*sGCOS\*n allows initialization of internal \fGstatic\fR
  509. (same syntax as for external definitions).
  510. .ti0
  511. g    C.5)    integer\(mi>... is not allowed on \*sGCOS\*n.
  512. .ti0
  513. g    C.6)    Some operators on pointers are illegal on \*sGCOS\*n (<, >).
  514. .ti0
  515. g    C.7)    \fGregister\fR storage class means something on \*sUNIX\*n,
  516. but is not accepted on \*sGCOS\*n.
  517. .ti0
  518. g    C.8)    Scope holes: ``int x; f^(^^)^{int x;}'' is illegal on
  519. \*sUNIX\*n but defines two variables on \*sGCOS\*n.
  520. .ti0
  521. g    C.9)    When function names are used as arguments on \*sUNIX\*n,
  522. either ``fname'' or ``&fname'' may be used to get a pointer to the function;
  523. on \*sGCOS\*n ``&fname'' generates a doubly-indirect pointer.
  524. (Note that both are wrong since the ``&''
  525. is supposed to be supplied for free.)
  526. .sp
  527. .ne 5
  528. .ti0
  529. .ft I
  530. D. Operating System Dependencies
  531. .sp
  532. .ft R
  533. .ti0
  534. d    D.1)    \*sGCOS\*n allocates external scalars by SYMREF;
  535. \*sUNIX\*n allocates external scalars as labelled common;
  536. as a result there may be many
  537. uninitialized external definitions of the same variable
  538. on \*sUNIX\*n but only one on \*sGCOS\*n.
  539. .ti0
  540. d    D.2)    External names differ in allowable length and
  541. character set;
  542. on \*sUNIX\*n, 7 characters and both cases; on \*sGCOS\*n
  543. 6 characters and only one case.
  544. .sp
  545. .ne 5
  546. .ft I
  547. .ti0
  548. E. Semantic Differences
  549. .ft R
  550. .sp
  551. .ti0
  552. hg    E.1)    ``int i, *p; p=i; i=p;'' does nothing on \*sUNIX\*n,
  553. does something on \*sGCOS\*n (destroys right half of i) .
  554. .ti0
  555. d    E.2)    ``>>'' means arithmetic shift on \*sUNIX\*n, logical on \*sGCOS\*n.
  556. .ti0
  557. d    E.3)    When a \fGchar\fR is converted to integer, the result is always
  558. positive on \*sGCOS\*n but can be negative on \*sUNIX\*n.
  559. .ti0
  560. d    E.4)    Arguments of subroutines are evaluated left-to-right
  561. on \*sGCOS\*n, right-to-left on \*sUNIX\*n.
  562.