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

  1. .ta .5i 1i 1.5i 2i 2.5i 3i 3.5i 4i
  2. .ul
  3. 1.  Introduction
  4. .et
  5. C is a computer language based on the earlier language B [1].
  6. The languages and their compilers differ in two
  7. major ways:
  8. C introduces the notion of types, and defines
  9. appropriate extra syntax and semantics;
  10. also, C on the \s8PDP\s10-11 is a true compiler, producing
  11. machine code where B produced interpretive code.
  12. .pg
  13. Most of the software for the \s8UNIX\s10 time-sharing system [2]
  14. is written in C, as is the operating system itself.
  15. C is also available on the \s8HIS\s10 6070 computer
  16. at Murray Hill and
  17. and on the \s8IBM\s10 System/370
  18. at Holmdel [3].
  19. This paper is a manual only for the C language itself
  20. as implemented on the \s8PDP\s10-11.
  21. However, hints are given occasionally in the text of
  22. implementation-dependent features.
  23. .pg
  24. The \s8UNIX\s10 Programmer's Manual [4]
  25. describes the library routines available to C programs under \s8UNIX\s10,
  26. and also the procedures for compiling programs under that
  27. system.
  28. ``The \s8GCOS\s10 C Library'' by Lesk and Barres [5]
  29. describes routines available under that system
  30. as well as compilation procedures.
  31. Many of these routines, particularly the ones having to do with I/O,
  32. are also provided under \s8UNIX\s10.
  33. Finally, ``Programming in C\(mi A Tutorial,''
  34. by B. W. Kernighan [6],
  35. is as useful as promised by its title and the author's
  36. previous introductions to allegedly impenetrable subjects.
  37. .ul
  38. 2.  Lexical conventions
  39. .et
  40. There are six kinds of
  41. tokens:
  42. identifiers, keywords, constants, strings, expression operators,
  43. and other separators.
  44. In general blanks, tabs, newlines,
  45. and comments as described below
  46. are ignored except as they serve to separate
  47. tokens.
  48. At least one of these characters is required to separate
  49. otherwise adjacent identifiers,
  50. constants, and certain operator-pairs.
  51. .pg
  52. If the input stream has been parsed into tokens
  53. up to a given character, the next token is taken
  54. to include the longest string of characters
  55. which could possibly constitute a token.
  56. .ms
  57. 2.1  Comments
  58. .et
  59. The characters ^^\fG/\**\fR^^ introduce a comment, which terminates
  60. with the characters^^ \fG\**/\fR.
  61. .ms
  62. 2.2  Identifiers (Names)
  63. .et
  64. An identifier is a sequence of letters and digits;
  65. the first character must be alphabetic.
  66. The underscore ``\(ru'' counts as alphabetic.
  67. Upper and lower case letters
  68. are considered different.
  69. No more than the first eight characters
  70. are significant, and only the first seven for
  71. external identifiers.
  72. .ms
  73. 2.3  Keywords
  74. .et
  75. The following identifiers are reserved for use
  76. as keywords, and may not be used otherwise:
  77. .sp .7
  78. .in .5i
  79. .ta 2i
  80. .nf
  81. .ne 10
  82. .ft G
  83. int    break
  84. char    continue
  85. float    if
  86. double    else
  87. struct    for
  88. auto    do
  89. extern    while
  90. register    switch
  91. static    case
  92. goto    default
  93. return    entry
  94. sizeof
  95. .sp .7
  96. .ft R
  97. .fi
  98. .in 0
  99. The
  100. .bd entry
  101. keyword is not currently implemented by any compiler but
  102. is reserved for future use.
  103. .ms
  104. 2.3  Constants
  105. .et
  106. There are several kinds
  107. of constants, as follows:
  108. .ms
  109. 2.3.1  Integer constants
  110. .et
  111. An integer constant is a sequence of digits.
  112. An integer is taken
  113. to be octal if it begins with \fG0\fR, decimal otherwise.
  114. The digits \fG8\fR and \fG9\fR have octal value 10 and 11 respectively.
  115. .ms
  116. 2.3.2  Character constants
  117. .et
  118. A character constant is 1 or 2 characters enclosed in single quotes
  119. ``\fG^\(aa^\fR''.
  120. Within a character constant a single quote must be preceded by
  121. a back-slash ``\\''.
  122. Certain non-graphic characters, and ``\\'' itself,
  123. may be escaped according to the following table:
  124. .sp .7
  125. .ta .5i 1.25i
  126. .nf
  127.     \s8BS\s10    \\b
  128.     \s8NL\s10    \\n
  129.     \s8CR\s10    \\r
  130.     \s8HT\s10    \\t
  131.     \fIddd\fR    \\\fIddd\fR
  132.     \\    \\\\
  133. .fi
  134. .sp .7
  135. The escape ``\\\fIddd\fR''
  136. consists of the backslash followed by 1, 2, or 3 octal digits
  137. which are taken to specify the value of the
  138. desired character.
  139. A special case of this construction is ``\\0'' (not followed
  140. by a digit) which indicates a null character.
  141. .pg
  142. Character constants behave exactly like integers
  143. (not, in particular, like objects
  144. of character type).
  145. In conformity with the addressing structure of the \s8PDP\s10-11,
  146. a character constant of length 1 has the code for the
  147. given character in the low-order byte
  148. and 0 in the high-order byte;
  149. a character constant of length 2 has the code for the
  150. first character in the low byte and that for the second
  151. character in the high-order byte.
  152. Character constants with more than one character are
  153. inherently machine-dependent and should
  154. be avoided.
  155. .ms
  156. 2.3.3  Floating constants
  157. .et
  158. A floating constant consists of
  159. an integer part, a decimal point, a fraction part,
  160. an \fGe\fR, and an optionally signed integer exponent.
  161. The integer and fraction parts both consist of a sequence
  162. of digits.
  163. Either the integer part or the fraction
  164. part (not both) may be missing;
  165. either the decimal point or
  166. the \fGe\fR and the exponent (not both) may be missing.
  167. Every floating constant is taken to be double-precision.
  168. .ms
  169. 2.4  Strings
  170. .et
  171. A string is a sequence of characters surrounded by
  172. double quotes ``^\fG"\fR^''.
  173. A string has the type
  174. array-of-characters (see below)
  175. and refers to an area of storage initialized with
  176. the given characters.
  177. The compiler places
  178. a null byte (^\\0^)
  179. at the end of each string so that programs
  180. which scan the string can
  181. find its end.
  182. In a string, the character ``^\fG"\fR^'' must be preceded by
  183. a ``\\''^;
  184. in addition, the same escapes as described for character
  185. constants may be used.
  186. .ul
  187. 3.  Syntax notation
  188. .et
  189. In the syntax notation used in this manual,
  190. syntactic categories are indicated by
  191. \fIitalic\fR type,
  192. and literal words and characters
  193. in \fGgothic.\fR
  194. Alternatives are listed on separate lines.
  195. An optional terminal or non-terminal symbol is
  196. indicated by the subscript ``opt,'' so that
  197. .dp
  198.     { expression\*(op }
  199. .ed
  200. would indicate an optional expression in braces.
  201. .ul
  202. 4.  What's in a Name?
  203. .et
  204. C bases the interpretation of an
  205. identifier upon two attributes of the identifier: its
  206. .ft I
  207. storage class
  208. .ft R
  209. and its
  210. .ft I
  211. type.
  212. .ft R
  213. The storage class determines the location and lifetime
  214. of the storage associated with an identifier;
  215. the type determines
  216. the meaning of the values
  217. found in the identifier's storage.
  218. .pg
  219. There are four declarable storage classes:
  220. automatic,
  221. static,
  222. external,
  223. and
  224. register.
  225. Automatic variables are local to each invocation of
  226. a function, and are discarded on return;
  227. static variables are local to a function, but retain
  228. their values independently of invocations of the
  229. function; external variables are independent of any function.
  230. Register variables are stored in the fast registers
  231. of the machine; like automatic
  232. variables they are local to each function and disappear on return.
  233. .pg
  234. C supports four fundamental types of objects:
  235. characters, integers, single-, and double-precision
  236. floating-point numbers.
  237. .sp .7
  238. .in .5i
  239. Characters (declared, and hereinafter called, \fGchar\fR) are chosen from
  240. the \s8ASCII\s10 set;
  241. they occupy the right-most seven bits
  242. of an 8-bit byte.
  243. It is also possible to interpret \fGchar\fRs
  244. as signed, 2's complement 8-bit numbers.
  245. .sp .4
  246. Integers (\fGint\fR) are represented in 16-bit 2's complement notation.
  247. .sp .4
  248. Single precision floating point (\fGfloat\fR) quantities
  249. have magnitude in the range approximately
  250. 10\u\s7\(+-38\s10\d
  251. or 0; their precision is 24 bits or about
  252. seven decimal digits.
  253. .sp .4
  254. Double-precision floating-point (\fGdouble\fR) quantities have the same range
  255. as \fGfloat\fRs and a precision of 56 bits
  256. or about 17 decimal digits.
  257. .sp .7
  258. .in 0
  259. .pg
  260. Besides the four fundamental types there is a
  261. conceptually infinite class of derived types constructed
  262. from the fundamental types in the following ways:
  263. .sp .7
  264. .in .5i
  265. .ft I
  266. arrays
  267. .ft R
  268. of objects of most types;
  269. .sp .4
  270. .ft I
  271. functions
  272. .ft R
  273. which return objects of a given type;
  274. .sp .4
  275. .ft I
  276. pointers
  277. .ft R
  278. to objects of a given type;
  279. .sp .4
  280. .ft I
  281. structures
  282. .ft R
  283. containing objects of various types.
  284. .sp .7
  285. .in 0
  286. In general these methods
  287. of constructing objects can
  288. be applied recursively.
  289. .ul
  290. 5.  Objects and lvalues
  291. .et
  292. An object is a manipulatable region of storage;
  293. an lvalue is an expression referring to an object.
  294. An obvious example of an lvalue
  295. expression is an identifier.
  296. There are operators which yield lvalues:
  297. for example,
  298. if E is an expression of pointer type, then \**E is an lvalue
  299. expression referring to the object to which E points.
  300. The name ``lvalue'' comes from the assignment expression
  301. ``E1@=@E2'' in which the left operand E1 must be
  302. an lvalue expression.
  303. The discussion of each operator
  304. below indicates whether it expects lvalue operands and whether it
  305. yields an lvalue.
  306. .ul
  307. 6.  Conversions
  308. .et
  309. A number of operators may, depending on their operands,
  310. cause conversion of the value of an operand from one type to another.
  311. This section explains the result to be expected from such
  312. conversions.
  313. .ms
  314. 6.1  Characters and integers
  315. .et
  316. A \fGchar\fR object may be used anywhere
  317. an \fGint\fR may be.
  318. In all cases the
  319. \fGchar\fR is converted to an \fGint\fR
  320. by propagating its sign through the
  321. upper 8 bits of the resultant integer.
  322. This is consistent with the two's complement representation
  323. used for both characters and integers.
  324. (However,
  325. the sign-propagation feature
  326. disappears in other implementations.)
  327. .ms
  328. 6.2  Float and double
  329. .et
  330. All floating arithmetic in C is carried out in double-precision;
  331. whenever a \fGfloat\fR
  332. appears in an expression it is lengthened to \fGdouble\fR
  333. by zero-padding its fraction.
  334. When a \fGdouble\fR must be
  335. converted to \fGfloat\fR, for example by an assignment,
  336. the \fGdouble\fR is rounded before
  337. truncation to \fGfloat\fR length.
  338. .ms
  339. 6.3  Float and double; integer and character
  340. .et
  341. All \fGint\fRs and \fGchar\fRs may be converted without
  342. loss of significance to \fGfloat\fR or \fGdouble\fR.
  343. Conversion of \fGfloat\fR or \fGdouble\fR
  344. to \fGint\fR or \fGchar\fR takes place with truncation towards 0.
  345. Erroneous results can be expected if the magnitude
  346. of the result exceeds 32,767 (for \fGint\fR)
  347. or 127 (for \fGchar\fR).
  348. .ms
  349. 6.4  Pointers and integers
  350. .et
  351. Integers and pointers may be added and compared; in such a case
  352. the \fGint\fR is converted as
  353. specified in the discussion of the addition operator.
  354. .pg
  355. Two pointers to objects of the same type may be subtracted;
  356. in this case the result is converted to an integer
  357. as specified in the discussion of the subtraction
  358. operator.
  359.