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

📄 appa.html

📁 c语言编程-c语言作者的书。英文原版。非常好。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
line, marked by the phrase ``one of.'' An optional terminal or nonterminalsymbol carries the subscript ``<em>opt</em>,'' so that, for example,<p  align="center">{ <em>expression<sub>opt</sub></em> }<p>means an optional expression, enclosed in braces. The syntax is summarized in<a href="#sa.13">Par.A.13</a>.<p><dl><dd><font size="-1">Unlike the grammar given in the first edition of this book, the one givenhere makes precedence and associativity of expression operators explicit.</font></dl><h2><a name="sa.4">A.4 Meaning of Identifiers</a></h2>Identifiers, or names, refer to a variety of things: functions; tags ofstructures, unions, and enumerations; members of structures or unions;enumeration constants; typedef names; and objects. An object, sometimescalled a variable, is a location in storage, and its interpretation dependson two main attributes: its <em>storage class</em> and its <em>type</em>. Thestorage class determines the lifetime of the storage associated with theidentified object; the type determines the meaning of the values found inthe identified object. A name also has a scope, which is the region of theprogram in which it is known, and a linkage, which determines whether thesame name in another scope refers to the same object or function. Scope andlinkage are discussed in <a href="#sa.11">Par.A.11</a>.<h3><a name="sa.4.1">A.4.1 Storage Class</a></h3>There are two storage classes: automatic and static. Several  keywords,together with the context of an object's declaration, specify its storageclass. Automatic objects are local to a block (<a href="#sa.9.3">Par.9.3</a>),and are discarded on exit from the block. Declarations within a block createautomatic objects if no storage class specification is mentioned, or if the<tt>auto</tt> specifier is used. Objects declared <tt>register</tt> are automatic,and are (if possible) stored in fast registers of the machine.<p>Static objects may be local to a block or external to all blocks, but ineither case retain their values across exit from and reentry to functionsand blocks. Within a block, including a block that provides the code for afunction, static objects are declared with the keyword <tt>static</tt>. Theobjects declared outside all blocks, at the same level as function definitions,are always static. They may be made local to a particular translation unit byuse of the <tt>static</tt> keyword; this gives them <em>internal linkage</em>.They become global to an entire program by omitting an explicit storage class,or by using the keyword <tt>extern</tt>; this gives them <em>external linkage</em>.<h3><a name="sa.4.2">A.4.2 Basic Types</a></h3>There are several fundamental types. The standard header <tt>&lt;limits.h&gt;</tt>described in <a href="appb.html">Appendix B</a> defines the largest and smallest valuesof each type in the local implementation. The numbers given in <a href="appb.html">Appendix B</a> show the smallest acceptable magnitudes.<p>Objects declared as characters (<tt>char</tt>) are large enough to store anymember of the execution character set. If a genuine character from that setis stored in a <tt>char</tt> object, its value is equivalent to the integer codefor the character, and is non-negative. Other quantities may be stored into<tt>char</tt> variables, but the available range of values, and especiallywhether the value is signed, is implementation-dependent.<p>Unsigned characters declared <tt>unsigned char</tt> consume the same amount ofspace as plain characters, but always appear non-negative; explicitly signedcharacters declared <tt>signed char</tt> likewise take the same space as plaincharacters.<p><dl><dd><font size="-1">unsigned <tt>char</tt> type does not appear in the first edition of this book, butis in common use. <tt>signed char</tt> is new.</font></dl><p>Besides the <tt>char</tt> types, up to three sizes of integer, declared <tt>shortint</tt>, <tt>int</tt>, and <tt>long int</tt>, are available. Plain <tt>int</tt> objectshave the natural size suggested by the host machine architecture; the othersizes are provided to meet special needs. Longer integers provide at least asmuch storage as shorter ones, but the implementation may make plain integersequivalent to either short integers, or long integers. The <tt>int</tt> typesall represent signed values unless specified otherwise.<p>Unsigned integers, declared using the keyword <tt>unsigned</tt>, obey the lawsof arithmetic modulo 2<sup><em>n</em></sup> where <em>n</em> is the number of bits inthe representation, and thus arithmetic on unsigned quantities can never overflow.The set of non-negative values that can be stored in a signed object is asubset of the values that can be stored in the corresponding unsigned object,and the representation for the overlapping values is the same.<p>Any of single precision floating point (<tt>float</tt>), double precision floatingpoint (<tt>double</tt>), and extra precision floating point (<tt>long double</tt>)may be synonymous, but the ones later in the list are at least as precise asthose before.<p><dl><dd><font size="-1"><tt>long double</tt> is new. The first edition made <tt>long float</tt> equivalentto <tt>double</tt>; the locution has been withdrawn.</font></dl><p><em>Enumerations</em> are unique types that have integral values; associatedwith each enumeration is a set of named constants (<a href="#sa.8.4">Par.A.8.4</a>).Enumerations behave like integers, but it is common for a compiler to issuea warning when an object of a particular enumeration is assigned somethingother than one of its constants, or an expression of its type.<p>Because objects of these types can be interpreted as numbers, they will bereferred to as <em>arithmetic</em> types. Types <tt>char</tt>, and <tt>int</tt> of allsizes, each with or without sign, and also enumeration types, will collectivelybe called <em>integral</em> types. The types <tt>float</tt>, <tt>double</tt>, and<tt>long double</tt> will be called <em>floating</em> types.<p>The <tt>void</tt> type specifies an empty set of values. It is used as the typereturned by functions that generate no value.<h3><a name="sa.4.3">A.4.3 Derived types</a></h3>Beside the basic types, there is a conceptually infinite class of derived typesconstructed from the fundamental types in the following ways:<p>&nbsp;&nbsp;<em>arrays</em> of objects of a given type;<br>&nbsp;&nbsp;<em>functions</em> returning objects of a given type;<br>&nbsp;&nbsp;<em>pointers</em> to objects of a given type;<br>&nbsp;&nbsp;<em>structures</em> containing a sequence of objects of various types;<br>&nbsp;&nbsp;<em>unions</em> capable of containing any of one of several objects of various types.<p>In general these methods of constructing objects can be applied recursively.<h3><a name="sa.4.4">A.4.4 Type Qualifiers</a></h3>An object's type may have additional qualifiers. Declaring an object<tt>const</tt> announces that its value will not be changed; declaring it<tt>volatile</tt> announces that it has special properties relevant tooptimization. Neither qualifier affects the range of values or arithmeticproperties of the object. Qualifiers are discussed in<a href="#sa.8.2">Par.A.8.2</a>.<h2><a name="sa.5">A.5 Objects and Lvalues</a></h2>An <em>Object</em> is a named region of storage; an <em>lvalue</em> is anexpression referring to an object. An obvious example of an lvalue expressionis an identifier with suitable type and storage class. There are operatorsthat yield lvalues, if <tt>E</tt> is an expression of pointer type, then<tt>*E</tt> is an lvalue expression referring to the object to which <tt>E</tt>points. The name ``lvalue'' comes from the assignment expression <tt>E1 = E2</tt>in which the left operand <tt>E1</tt> must be an lvalue expression. Thediscussion of each operator specifies whether it expects lvalue operands andwhether it yields an lvalue.<h2><a name="sa.6">A.6 Conversions</a></h2>Some operators may, depending on their operands, cause conversion of thevalue of an operand from one type to another. This section explains theresult to be expected from such conversions. <a href="#sa.6.5">Par.6.5</a>summarizes the conversions demanded by most ordinary operators; it will besupplemented as required by the discussion of each operator.<h3><a name="sa.6.1">A.6.1 Integral Promotion</a></h3>A character, a short integer, or an integer bit-field, all either signed ornot, or an object of enumeration type, may be used in an expression whereveran integer may be used. If an <tt>int</tt> can represent all the values of theoriginal type, then the value is converted to <tt>int</tt>; otherwise the value isconverted to <tt>unsigned int</tt>. This process is called <em>integralpromotion</em>.<h3><a name="sa.6.2">A.6.2 Integral Conversions</a></h3>Any integer is converted to a given unsigned type by finding the smallestnon-negative value that is congruent to that integer, modulo one more than thelargest value that can be represented in the unsigned type. In a two'scomplement representation, this is equivalent to left-truncation if the bitpattern of the unsigned type is narrower, and to zero-filling unsigned valuesand sign-extending signed values if the unsigned type is wider.<p>When any integer is converted to a signed type, the value is unchanged if itcan be represented in the new type and is implementation-defined otherwise.<h3><a name="sa.6.3">A.6.3 Integer and Floating</a></h3>When a value of floating type is converted to integral type, the fractionalpart is discarded; if the resulting value cannot be represented in theintegral type, the behavior is undefined. In particular, the result ofconverting negative floating values to unsigned integral types is notspecified.<p>When a value of integral type is converted to floating, and the value is in therepresentable range but is not exactly representable, then the result may beeither the next higher or next lower representable value. If the result is outof range, the behavior is undefined.<h3><a name="sa.6.4">A.6.4 Floating Types</a></h3>When a less precise floating value is converted to an equally or more precisefloating type, the value is unchanged. When a more precise floating value isconverted to a less precise floating type, and the value is withinrepresentable range, the result may be either the next higher or the next lowerrepresentable value. If the result is out of range, the behavior is undefined.<h3><a name="sa.6.5">A.6.5 Arithmetic Conversions</a></h3>Many operators cause conversions and yield result types in a similar way. Theeffect is to bring operands into a common type, which is also the type of theresult. This pattern is called the <em>usual arithmetic conversions</em>.<p><ul><li>First, if either operand is <tt>long double</tt>, the other is converted    to <tt>long double</tt>.<li>Otherwise, if either operand is <tt>double</tt>, the other is converted    to <tt>double</tt>.<li>Otherwise, if either operand is <tt>float</tt>, the other is converted to    <tt>float</tt>.<li>Otherwise, the integral promotions are performed on both operands; then,    if either operand is <tt>unsigned long int</tt>, the other is converted to    <tt>unsigned long int</tt>.<li>Otherwise, if one operand is <tt>long int</tt> and the other is    <tt>unsigned int</tt>, the effect depends on whether a <tt>long int</tt>    can represent all values of an <tt>unsigned int</tt>; if so, the    <tt>unsigned int</tt> operand is converted to <tt>long int</tt>; if not,    both are converted to <tt>unsigned long int</tt>.<li>Otherwise, if one operand is <tt>long int</tt>, the other is converted to    <tt>long int</tt>.<li>Otherwise, if either operand is <tt>unsigned int</tt>, the other is    converted to <tt>unsigned int</tt>.<li>Otherwise, both operands have type <tt>int</tt>.</ul><p><dl><dd><font size="-1">There are two changes here. First, arithmetic on <tt>float</tt> operands may bedone in single precision, rather than double; the first edition specified thatall floating arithmetic was double precision. Second, shorter unsigned types,when combined with a larger signed type, do not propagate the unsigned propertyto the result type; in the first edition, the unsigned always dominated. Thenew rules are slightly more complicated, but reduce somewhat the surprisesthat may occur when an unsigned quantity meets signed. Unexpected results maystill occur when an unsigned expression is compared to a signed expression ofthe same size.</font></dl><h3><a name="sa.6.6">A.6.6 Pointers and Integers</a></h3>An expression of integral type may be added to or subtracted from a pointer;in such a case the integral expression is converted as specified in thediscussion of the addition operator (<a href="#sa.7.7">Par.A.7.7</a>).<p>Two pointers to objects of the same type, in the same array, may besubtracted; the result is converted to an integer as specified in thediscussion of the subtraction operator (<a href="#sa.7.7">Par.A.7.7</a>).<p>An integral constant expression with value 0, or such an expression cast to

⌨️ 快捷键说明

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