ISO C11 标准中的左值
lvalues in the ISO C11 standard
§ 6.3.2.1:2 of ISO/IEC 9899:2011,即“ISO C11 标准”,说:
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); this is called lvalue conversion. If the
lvalue has qualified type, the value has the unqualified version of
the type of the lvalue; additionally, if the lvalue has atomic type,
the value has the non-atomic 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. If the lvalue designates an object of automatic storage
duration that could have been declared with the register storage class
(never had its address taken), and that object is uninitialized (not
declared with an initializer and no assignment to it has been
performed prior to use), the behavior is undefined.
但是取消引用的指针不也是左值,就像指针本身一样吗?例如。 int *ptr; ptr = malloc(…); *ptr = 1
那么为什么没有提到 *
运算符——或者我在这里混淆了什么?
您错过了第 6.5.3.2p4 节,该节讨论了间接运算符的语义 *
:
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.
运算符本身被定义为产生左值。
§ 6.3.2.1:2 of ISO/IEC 9899:2011,即“ISO C11 标准”,说:
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); this is called lvalue conversion. If the lvalue has qualified type, the value has the unqualified version of the type of the lvalue; additionally, if the lvalue has atomic type, the value has the non-atomic 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. If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized (not declared with an initializer and no assignment to it has been performed prior to use), the behavior is undefined.
但是取消引用的指针不也是左值,就像指针本身一样吗?例如。 int *ptr; ptr = malloc(…); *ptr = 1
那么为什么没有提到 *
运算符——或者我在这里混淆了什么?
您错过了第 6.5.3.2p4 节,该节讨论了间接运算符的语义 *
:
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.
运算符本身被定义为产生左值。