- 论坛徽章:
- 0
|
条件运算,表达式最终的值的类型是?
原帖由 "小水平" 发表:
请给个有依据的准确说法.
“有依据的准确说法”如下 :
c99 “6.5.15 Conditional operator”
The first operand is evaluated; there is a sequence point after its evaluation. The second
operand is evaluated only if the first compares unequal to 0; the third operand is evaluated
only 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.92) If an attempt is made
to modify the result of a conditional operator or to access it after the next sequence point,
the behavior is undefined.
If both the second and third operands have arithmetic type, the result type that would be
determined 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 has
that type. If both operands have void type, the result has void type.
If both the second and third operands are pointers or one is a null pointer constant and the
other is a pointer, the result type is a pointer to a type qualified with all the type qualifiers
of the types pointed-to by both operands. Furthermore, if both operands are pointers to
compatible types or to differently qualified versions of compatible types, the result type is
a pointer to an appropriately qualified version of the composite type; if one operand is a
null pointer constant, the result has the type of the other operand; otherwise, one operand
is a pointer to void or a qualified version of void, in which case the result type is a pointer to
an appropriately qualified version of void.
 |
|