[ Pobierz całość w formacie PDF ]
.The types float, double, andlong double will be called floating types.The void type specifies an empty set of values.It is used as the type returned by functionsthat generate no value.A.4.3 Derived typesBeside the basic types, there is a conceptually infinite class of derived types constructed fromthe fundamental types in the following ways:arrays of objects of a given type;functions returning objects of a given type;pointers to objects of a given type;structures containing a sequence of objects of various types;unions capable of containing any of one of several objects of various types.In general these methods of constructing objects can be applied recursively.A.4.4 Type QualifiersAn object's type may have additional qualifiers.Declaring an object const announces that itsvalue will not be changed; declaring it volatile announces that it has special propertiesrelevant to optimization.Neither qualifier affects the range of values or arithmetic propertiesof the object.Qualifiers are discussed in Par.A.8.2.A.5 Objects and LvaluesAn Object is a named region of storage; an lvalue is an expression referring to an object.Anobvious example of an lvalue expression is an identifier with suitable type and storage class.There are operators that yield lvalues, 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 theassignment expression E1 = E2 in which the left operand E1 must be an lvalue expression.The discussion of each operator specifies whether it expects lvalue operands and whether ityields an lvalue.A.6 ConversionsSome operators may, depending on their operands, cause conversion of the value of anoperand from one type to another.This section explains the result to be expected from such174conversions.Par.6.5 summarizes the conversions demanded by most ordinary operators; itwill be supplemented as required by the discussion of each operator.A.6.1 Integral PromotionA character, a short integer, or an integer bit-field, all either signed or not, or an object ofenumeration type, may be used in an expression wherever an integer may be used.If an intcan represent all the values of the original type, then the value is converted to int; otherwisethe value is converted to unsigned int.This process is called integral promotion.A.6.2 Integral ConversionsAny integer is converted to a given unsigned type by finding the smallest non-negative valuethat is congruent to that integer, modulo one more than the largest value that can berepresented in the unsigned type.In a two's complement representation, this is equivalent toleft-truncation if the bit pattern of the unsigned type is narrower, and to zero-filling unsignedvalues and sign-extending signed values if the unsigned type is wider.When any integer is converted to a signed type, the value is unchanged if it can be representedin the new type and is implementation-defined otherwise.A.6.3 Integer and FloatingWhen a value of floating type is converted to integral type, the fractional part is discarded; ifthe resulting value cannot be represented in the integral type, the behavior is undefined.Inparticular, the result of converting negative floating values to unsigned integral types is notspecified.When a value of integral type is converted to floating, and the value is in the representablerange but is not exactly representable, then the result may be either the next higher or nextlower representable value.If the result is out of range, the behavior is undefined.A.6.4 Floating TypesWhen a less precise floating value is converted to an equally or more precise floating type, thevalue is unchanged.When a more precise floating value is converted to a less precise floatingtype, and the value is within representable range, the result may be either the next higher orthe next lower representable value.If the result is out of range, the behavior is undefined.A.6.5 Arithmetic ConversionsMany operators cause conversions and yield result types in a similar way.The effect is tobring operands into a common type, which is also the type of the result.This pattern is calledthe usual arithmetic conversions." First, if either operand is long double, the other is converted to long double." Otherwise, if either operand is double, the other is converted to double." Otherwise, if either operand is float, the other is converted to float." Otherwise, the integral promotions are performed on both operands; then, if eitheroperand is unsigned long int, the other is converted to unsigned long int.175" Otherwise, if one operand is long int and the other is unsigned int, the effectdepends on whether a long int can represent all values of an unsigned int; if so,the unsigned int operand is converted to long int; if not, both are converted tounsigned long int." Otherwise, if one operand is long int, the other is converted to long int." Otherwise, if either operand is unsigned int, the other is converted to unsignedint." Otherwise, both operands have type int.There are two changes here.First, arithmetic on float operands may be done in single precision,rather than double; the first edition specified that all floating arithmetic was double precision.Second,shorter unsigned types, when combined with a larger signed type, do not propagate the unsignedproperty to the result type; in the first edition, the unsigned always dominated.The new rules areslightly more complicated, but reduce somewhat the surprises that may occur when an unsignedquantity meets signed.Unexpected results may still occur when an unsigned expression is compared toa signed expression of the same size.A.6.6 Pointers and IntegersAn expression of integral type may be added to or subtracted from a pointer; in such a casethe integral expression is converted as specified in the discussion of the addition operator(Par.A.7.7).Two pointers to objects of the same type, in the same array, may be subtracted; the result isconverted to an integer as specified in the discussion of the subtraction operator (Par.A.7.7).An integral constant expression with value 0, or such an expression cast to type void *, maybe converted, by a cast, by assignment, or by comparison, to a pointer of any type.Thisproduces a null pointer that is equal to another null pointer of the same type, but unequal toany pointer to a function or object.Certain other conversions involving pointers are permitted, but have implementation-definedaspects.They must be specified by an explicit type-conversion operator, or cast (Pars.A.7.5and A.8.8)
[ Pobierz całość w formacie PDF ]