- 论坛徽章:
- 0
|
这是标准写的, 确实大家对左值理解都不一样,所以讨论也没什么对错可言了
An lvalue is an expression with an object type or an incomplete type other than void;
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.
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
The cast and assignment operators are still required to perform their specified conversions as
described in 6.3.1.4 and 6.3.1.5.
The name ‘‘lvalue’’ comes originally ---------------------------
from the assignment expression E1 = E2, in which the left
operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an
object ‘‘locator value’’. What is sometimes called ‘‘rvalue’’ is in this International Standard described
as the ‘‘value of an expression’’.
An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary
expression that is a pointer to an object, *E is an lvalue that designates the object to which E points.
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.
Except when it is the operand of the sizeof operator or the unary & operator, or is a
string literal used to initialize an array, an expression that has type ‘‘array of type’’ is
converted to an expression with type ‘‘pointer to type’’ that points to the initial element of
the array object and is ___not ____ an lvalue.
这段话说 T t[N], t的类型大多数时候是 T*, 而且它不是左值, 同样int a[2][3]; *a hash type of "array of int" , so converted to int *, and is not an lvalue
K&R也是这个意思, 这也是我上面帖子的来源参考
不管怎么理解左值,标准这一段(上面几段我不知所言)确实说int a[2][3]; *a不是左值
C语言参考手册基本就是抄标准的吧,我这里也有,没怎么看过,很像
KBTiller 写的不错,也和标准也很像 |
|