⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c1

📁 UNIX版本6的源代码
💻
字号:
.ta .5i 1i 1.5i 2i 2.5i 3i 3.5i 4i.ul1.  Introduction.etC is a computer language based on the earlier language B [1].The languages and their compilers differ in twomajor ways:C introduces the notion of types, and definesappropriate extra syntax and semantics;also, C on the \s8PDP\s10-11 is a true compiler, producingmachine code where B produced interpretive code..pgMost of the software for the \s8UNIX\s10 time-sharing system [2]is written in C, as is the operating system itself.C is also available on the \s8HIS\s10 6070 computerat Murray Hill andand on the \s8IBM\s10 System/370at Holmdel [3].This paper is a manual only for the C language itselfas implemented on the \s8PDP\s10-11.However, hints are given occasionally in the text ofimplementation-dependent features..pgThe \s8UNIX\s10 Programmer's Manual [4]describes the library routines available to C programs under \s8UNIX\s10,and also the procedures for compiling programs under thatsystem.``The \s8GCOS\s10 C Library'' by Lesk and Barres [5]describes routines available under that systemas well as compilation procedures.Many of these routines, particularly the ones having to do with I/O,are also provided under \s8UNIX\s10.Finally, ``Programming in C\(mi A Tutorial,''by B. W. Kernighan [6],is as useful as promised by its title and the author'sprevious introductions to allegedly impenetrable subjects..ul2.  Lexical conventions.etThere are six kinds oftokens:identifiers, keywords, constants, strings, expression operators,and other separators.In general blanks, tabs, newlines,and comments as described beloware ignored except as they serve to separatetokens.At least one of these characters is required to separateotherwise adjacent identifiers,constants, and certain operator-pairs..pgIf the input stream has been parsed into tokensup to a given character, the next token is takento include the longest string of characterswhich could possibly constitute a token..ms2.1  Comments.etThe characters ^^\fG/\**\fR^^ introduce a comment, which terminateswith the characters^^ \fG\**/\fR..ms2.2  Identifiers (Names).etAn identifier is a sequence of letters and digits;the first character must be alphabetic.The underscore ``\(ru'' counts as alphabetic.Upper and lower case lettersare considered different.No more than the first eight charactersare significant, and only the first seven forexternal identifiers..ms2.3  Keywords.etThe following identifiers are reserved for useas keywords, and may not be used otherwise:.sp .7.in .5i.ta 2i.nf.ne 10.ft Gint	breakchar	continuefloat	ifdouble	elsestruct	forauto	doextern	whileregister	switchstatic	casegoto	defaultreturn	entrysizeof.sp .7.ft R.fi.in 0The.bd entrykeyword is not currently implemented by any compiler butis reserved for future use..ms2.3  Constants.etThere are several kindsof constants, as follows:.ms2.3.1  Integer constants.etAn integer constant is a sequence of digits.An integer is takento be octal if it begins with \fG0\fR, decimal otherwise.The digits \fG8\fR and \fG9\fR have octal value 10 and 11 respectively..ms2.3.2  Character constants.etA character constant is 1 or 2 characters enclosed in single quotes``\fG^\(aa^\fR''.Within a character constant a single quote must be preceded bya back-slash ``\\''.Certain non-graphic characters, and ``\\'' itself,may be escaped according to the following table:.sp .7.ta .5i 1.25i.nf	\s8BS\s10	\\b	\s8NL\s10	\\n	\s8CR\s10	\\r	\s8HT\s10	\\t	\fIddd\fR	\\\fIddd\fR	\\	\\\\.fi.sp .7The escape ``\\\fIddd\fR''consists of the backslash followed by 1, 2, or 3 octal digitswhich are taken to specify the value of thedesired character.A special case of this construction is ``\\0'' (not followedby a digit) which indicates a null character..pgCharacter constants behave exactly like integers(not, in particular, like objectsof character type).In conformity with the addressing structure of the \s8PDP\s10-11,a character constant of length 1 has the code for thegiven character in the low-order byteand 0 in the high-order byte;a character constant of length 2 has the code for thefirst character in the low byte and that for the secondcharacter in the high-order byte.Character constants with more than one character areinherently machine-dependent and shouldbe avoided..ms2.3.3  Floating constants.etA floating constant consists ofan integer part, a decimal point, a fraction part,an \fGe\fR, and an optionally signed integer exponent.The integer and fraction parts both consist of a sequenceof digits.Either the integer part or the fractionpart (not both) may be missing;either the decimal point orthe \fGe\fR and the exponent (not both) may be missing.Every floating constant is taken to be double-precision..ms2.4  Strings.etA string is a sequence of characters surrounded bydouble quotes ``^\fG"\fR^''.A string has the typearray-of-characters (see below)and refers to an area of storage initialized withthe given characters.The compiler placesa null byte (^\\0^)at the end of each string so that programswhich scan the string canfind its end.In a string, the character ``^\fG"\fR^'' must be preceded bya ``\\''^;in addition, the same escapes as described for characterconstants may be used..ul3.  Syntax notation.etIn the syntax notation used in this manual,syntactic categories are indicated by\fIitalic\fR type,and literal words and charactersin \fGgothic.\fRAlternatives are listed on separate lines.An optional terminal or non-terminal symbol isindicated by the subscript ``opt,'' so that.dp	{ expression\*(op }.edwould indicate an optional expression in braces..ul4.  What's in a Name?.etC bases the interpretation of anidentifier upon two attributes of the identifier: its.ft Istorage class.ft Rand its.ft Itype..ft RThe storage class determines the location and lifetimeof the storage associated with an identifier;the type determinesthe meaning of the valuesfound in the identifier's storage..pgThere are four declarable storage classes:automatic,static,external,andregister.Automatic variables are local to each invocation ofa function, and are discarded on return;static variables are local to a function, but retaintheir values independently of invocations of thefunction; external variables are independent of any function.Register variables are stored in the fast registersof the machine; like automaticvariables they are local to each function and disappear on return..pgC supports four fundamental types of objects:characters, integers, single-, and double-precisionfloating-point numbers..sp .7.in .5iCharacters (declared, and hereinafter called, \fGchar\fR) are chosen fromthe \s8ASCII\s10 set;they occupy the right-most seven bitsof an 8-bit byte.It is also possible to interpret \fGchar\fRsas signed, 2's complement 8-bit numbers..sp .4Integers (\fGint\fR) are represented in 16-bit 2's complement notation..sp .4Single precision floating point (\fGfloat\fR) quantitieshave magnitude in the range approximately10\u\s7\(+-38\s10\dor 0; their precision is 24 bits or aboutseven decimal digits..sp .4Double-precision floating-point (\fGdouble\fR) quantities have the same rangeas \fGfloat\fRs and a precision of 56 bitsor about 17 decimal digits..sp .7.in 0.pgBesides the four fundamental types there is aconceptually infinite class of derived types constructedfrom the fundamental types in the following ways:.sp .7.in .5i.ft Iarrays.ft Rof objects of most types;.sp .4.ft Ifunctions.ft Rwhich return objects of a given type;.sp .4.ft Ipointers.ft Rto objects of a given type;.sp .4.ft Istructures.ft Rcontaining objects of various types..sp .7.in 0In general these methodsof constructing objects canbe applied recursively..ul5.  Objects and lvalues.etAn object is a manipulatable region of storage;an lvalue is an expression referring to an object.An obvious example of an lvalueexpression is an identifier.There are operators which yield lvalues:for example,if E is an expression of pointer type, then \**E is an lvalueexpression referring to the object to which E points.The name ``lvalue'' comes from the assignment expression``E1@=@E2'' in which the left operand E1 must bean lvalue expression.The discussion of each operatorbelow indicates whether it expects lvalue operands and whether ityields an lvalue..ul6.  Conversions.etA number of operators may, depending on their operands,cause conversion of the value of an operand from one type to another.This section explains the result to be expected from suchconversions..ms6.1  Characters and integers.etA \fGchar\fR object may be used anywherean \fGint\fR may be.In all cases the\fGchar\fR is converted to an \fGint\fRby propagating its sign through theupper 8 bits of the resultant integer.This is consistent with the two's complement representationused for both characters and integers.(However,the sign-propagation featuredisappears in other implementations.).ms6.2  Float and double.etAll floating arithmetic in C is carried out in double-precision;whenever a \fGfloat\fRappears in an expression it is lengthened to \fGdouble\fRby zero-padding its fraction.When a \fGdouble\fR must beconverted to \fGfloat\fR, for example by an assignment,the \fGdouble\fR is rounded beforetruncation to \fGfloat\fR length..ms6.3  Float and double; integer and character.etAll \fGint\fRs and \fGchar\fRs may be converted withoutloss of significance to \fGfloat\fR or \fGdouble\fR.Conversion of \fGfloat\fR or \fGdouble\fRto \fGint\fR or \fGchar\fR takes place with truncation towards 0.Erroneous results can be expected if the magnitudeof the result exceeds 32,767 (for \fGint\fR)or 127 (for \fGchar\fR)..ms6.4  Pointers and integers.etIntegers and pointers may be added and compared; in such a casethe \fGint\fR is converted asspecified in the discussion of the addition operator..pgTwo pointers to objects of the same type may be subtracted;in this case the result is converted to an integeras specified in the discussion of the subtractionoperator.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -