简体   繁体   English

低于ISO C11标准的左值

[英]lvalues in the ISO C11 standard

§ 6.3.2.1:2 of ISO/IEC 9899:2011, ie the “ISO C11 standard”, says: ISO / IEC 9899:2011的第6.3.2.1:2节,即“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 . 2除非它是sizeof运算符的操作数,一元&运算符, ++运算符, --运算符或者左运算符. 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. 如果左值指定了一个自动存储持续时间的对象,该对象可以使用寄存器存储类声明(从未使用过其地址),并且该对象未初始化(未使用初始化程序声明,并且在使用之前未对其进行任何赋值) ),行为未定义。

But isn't a dereferenced pointer also an lvalue, just like the pointer itself? 但是不是一个解除引用的指针也是一个左值,就像指针本身一样? Eg int *ptr; ptr = malloc(…); *ptr = 1 例如int *ptr; ptr = malloc(…); *ptr = 1 int *ptr; ptr = malloc(…); *ptr = 1

So why is the * operator not mentioned – or do I confuse something here? 那么为什么没有提到*运算符 - 或者我在这里混淆了什么?

You're missing section 6.5.3.2p4, which discusses the semantics of indirection operator * : 您缺少第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". 如果操作数的类型为“指向类型的指针”,则结果的类型为“type”。 If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined. 如果为指针分配了无效值,则unary *运算符的行为未定义。

The operator itself is defined to produce an lvalue. 运算符本身被定义为产生左值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM