- 论坛徽章:
- 0
|
原帖由 shihyu 于 2009-3-14 08:10 发表
++i 在C 为什么不是左值 , 但是在C++ 是左值
#include
int main(void)
{
int c = 0;
++c = 100;
printf("c = %d\n",c);
return 0;
}
gcc 无法编译 ...
C标准规定的. 在 6.3.2节中
1 Anlvalue is an expression with an object type or an incomplete type other than void;53)
if an lvalue does not designate an object when it is evaluated, the behavior is undefined.
When an object is said to have a particular type, the type is specified by the lvalue used to
designate the object. A modifiable lvalue is an lvalue that does not have array type, does
not have an incomplete type, does not have a const-qualified type, and if it is a structure
or union, does not have any member (including, recursively, any member or element of
all contained aggregates or unions) with a const-qualified type.
2 Except when it is the operand of the sizeof operator, the unary & operator, the ++
operator, the -- operator, or the left operand of the . operator or an assignment operator,
an lvalue that does not have array type is converted to the value stored in the designated
object (and is no longer an lvalue). If the lvalue has qualified type, the value has the
unqualified version of the type of the lvalue; otherwise, the value has the type of the
lvalue. If the lvalue has an incomplete type and does not have array type, the behavior is
undefined. |
|