Стандарт языка Си С99 TC (1113411), страница 21
Текст из файла (страница 21)
The result has type int. For any pair ofoperands, exactly one of the relations is true.4If both of the operands have arithmetic type, the usual arithmetic conversions areperformed. Values of complex types are equal if and only if both their real parts are equaland also their imaginary parts are equal. Any two values of arithmetic types fromdifferent type domains are equal if and only if the results of their conversions to the(complex) result type determined by the usual arithmetic conversions are equal.92) The expression a<b<c is not interpreted as in ordinary mathematics.
As the syntax indicates, itmeans (a<b)<c; in other words, ‘‘if a is less than b, compare 1 to c; otherwise, compare 0 to c’’.93) Because of the precedences, a<b == c<d is 1 whenever a<b and c<d have the same truth-value.86Language§6.5.9WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC35Otherwise, at least one operand is a pointer. If one operand is a pointer and the other is anull pointer constant, the null pointer constant is converted to the type of the pointer.
Ifone operand is a pointer to an object or incomplete type and the other is a pointer to aqualified or unqualified version of void, the former is converted to the type of the latter.6Two pointers compare equal if and only if both are null pointers, both are pointers to thesame object (including a pointer to an object and a subobject at its beginning) or function,both are pointers to one past the last element of the same array object, or one is a pointerto one past the end of one array object and the other is a pointer to the start of a differentarray object that happens to immediately follow the first array object in the addressspace.94)7For the purposes of these operators, a pointer to an object that is not an element of anarray behaves the same as a pointer to the first element of an array of length one with thetype of the object as its element type.6.5.10 Bitwise AND operatorSyntax1AND-expression:equality-expressionAND-expression & equality-expressionConstraints2Each of the operands shall have integer type.Semantics3The usual arithmetic conversions are performed on the operands.4The result of the binary & operator is the bitwise AND of the operands (that is, each bit inthe result is set if and only if each of the corresponding bits in the converted operands isset).94) Two objects may be adjacent in memory because they are adjacent elements of a larger array oradjacent members of a structure with no padding between them, or because the implementation choseto place them so, even though they are unrelated.
If prior invalid pointer operations (such as accessesoutside array bounds) produced undefined behavior, subsequent comparisons also produce undefinedbehavior.§6.5.10Language87ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12566.5.11 Bitwise exclusive OR operatorSyntax1exclusive-OR-expression:AND-expressionexclusive-OR-expression ^ AND-expressionConstraints2Each of the operands shall have integer type.Semantics3The usual arithmetic conversions are performed on the operands.4The result of the ^ operator is the bitwise exclusive OR of the operands (that is, each bitin the result is set if and only if exactly one of the corresponding bits in the convertedoperands is set).6.5.12 Bitwise inclusive OR operatorSyntax1inclusive-OR-expression:exclusive-OR-expressioninclusive-OR-expression | exclusive-OR-expressionConstraints2Each of the operands shall have integer type.Semantics3The usual arithmetic conversions are performed on the operands.4The result of the | operator is the bitwise inclusive OR of the operands (that is, each bit inthe result is set if and only if at least one of the corresponding bits in the convertedoperands is set).88Language§6.5.12WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC36.5.13 Logical AND operatorSyntax1logical-AND-expression:inclusive-OR-expressionlogical-AND-expression && inclusive-OR-expressionConstraints2Each of the operands shall have scalar type.Semantics3The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, ityields 0.
The result has type int.4Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation;there is a sequence point after the evaluation of the first operand. If the first operandcompares equal to 0, the second operand is not evaluated.6.5.14 Logical OR operatorSyntax1logical-OR-expression:logical-AND-expressionlogical-OR-expression || logical-AND-expressionConstraints2Each of the operands shall have scalar type.Semantics3The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, ityields 0.
The result has type int.4Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; there isa sequence point after the evaluation of the first operand. If the first operand comparesunequal to 0, the second operand is not evaluated.§6.5.14Language89ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12566.5.15 Conditional operatorSyntax1conditional-expression:logical-OR-expressionlogical-OR-expression ? expression : conditional-expressionConstraints2The first operand shall have scalar type.3One of the following shall hold for the second and third operands:— both operands have arithmetic type;— both operands have the same structure or union type;— both operands have void type;— both operands are pointers to qualified or unqualified versions of compatible types;— one operand is a pointer and the other is a null pointer constant; or— one operand is a pointer to an object or incomplete type and the other is a pointer to aqualified or unqualified version of void.Semantics4The first operand is evaluated; there is a sequence point after its evaluation.
The secondoperand is evaluated only if the first compares unequal to 0; the third operand is evaluatedonly if the first compares equal to 0; the result is the value of the second or third operand(whichever is evaluated), converted to the type described below.95) If an attempt is madeto modify the result of a conditional operator or to access it after the next sequence point,the behavior is undefined.5If both the second and third operands have arithmetic type, the result type that would bedetermined by the usual arithmetic conversions, were they applied to those two operands,is the type of the result.
If both the operands have structure or union type, the result hasthat type. If both operands have void type, the result has void type.6If both the second and third operands are pointers or one is a null pointer constant and theother is a pointer, the result type is a pointer to a type qualified with all the type qualifiersof the types pointed-to by both operands.
Furthermore, if both operands are pointers tocompatible types or to differently qualified versions of compatible types, the result type isa pointer to an appropriately qualified version of the composite type; if one operand is anull pointer constant, the result has the type of the other operand; otherwise, one operandis a pointer to void or a qualified version of void, in which case the result type is a95) A conditional expression does not yield an lvalue.90Language§6.5.15WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3pointer to an appropriately qualified version of void.7EXAMPLE The common type that results when the second and third operands are pointers is determinedin two independent stages.
The appropriate qualifiers, for example, do not depend on whether the twopointers have compatible types.8Given the declarationsconst void *c_vp;void *vp;const int *c_ip;volatile int *v_ip;int *ip;const char *c_cp;the third column in the following table is the common type that is the result of a conditional expression inwhich the first two columns are the second and third operands (in either order):c_vpv_ipc_ipvpipvpc_ip0v_ipc_cpc_ipipconst void *volatile int *const volatile int *const void *const int *void *6.5.16 Assignment operatorsSyntax1assignment-expression:conditional-expressionunary-expression assignment-operator assignment-expressionassignment-operator: one of= *= /= %= +=-=<<=>>=&=^=|=Constraints2An assignment operator shall have a modifiable lvalue as its left operand.Semantics3An assignment operator stores a value in the object designated by the left operand.