- 论坛徽章:
- 5
|
本帖最后由 starwing83 于 2010-06-19 14:47 编辑
这个事儿嘛。其实是有两个方面的考虑的:
6.2.5.19 The void type comprises an empty set of values; it is an incomplete type that cannot be completed.
6.5.3.2.4 The unary * operator denotes indirection. If the operand points to a function, the result is
a function designator; if it points to an object, the result is an lvalue designating the
object. If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’. If an
invalid value has been assigned to the pointer, the behavior of the unary * operator is
undefined.84)
所以,其实*p这个操作本身是合法的。它的类型为void,问题是,void被定义成了一个不完全类型,然而:
6.5.6.2 For addition, either both operands shall have arithmetic type, or one operand shall be a
pointer to an object type and the other shall have integer type. (Incrementing is
equivalent to adding 1.)
因此,实际上真正的错误是类型不匹配的错误:+运算符需要两个arithmetic type,或者至少一个pointer一个Integer,你却给了一个void,显然就error了。
赋值的情况与之类似。 |
|