简体   繁体   English

C11中的后缀和前缀递增和递减表达式是左值吗?

[英]Are postfix and prefix increment and decrement expressions lvalues in C11?

Are postfix and prefix increment and decrement expressions lvalues in C11? C11中的后缀和前缀递增和递减表达式是左值吗? Usually the standard has notes at the bottom specifying whether or not a given expression is an lvalue. 通常,标准在底部有注释,用于指定给定表达式是否为左值。 I can not find anything in the standard in this case. 在这种情况下,我找不到标准中的任何内容。

I know that most of the time there would be sequence point issues, but there are some edge cases where it seems like it could be useful to know this. 我知道大多数时候会出现序列点问题,但是在某些极端情况下,了解这一点似乎很有用。 For example, in 6.5.2.4: 例如,在6.5.2.4中:

Postfix ++ on an object with atomic type is a read-modify-write operation with memory_order_seq_cst memory order semantics. 具有原子类型的对象上的Postfix ++是具有memory_order_seq_cst内存顺序语义的读-修改-写操作。

It follows that with an atomic type, something like ++x=x+y will be a pithy way to do something. 因此,对于原子类型,类似++ x = x + y的方法将是一种巧妙的方法。 Not that it would be important to be able to do such a thing, I just don't like not knowing things. 并不是能够做到这样的事情很重要,我只是不喜欢不了解事情。

This aspect of behavior of postfix and prefix increment and decrement operators is specified through the portion of standard document dedicated to additive operators and assignment operators. 后缀和前缀递增和递减运算符的行为方式是通过标准文档中专门用于加法运算符和赋值运算符的部分指定的。

In case of postfix operators 对于后缀运算符

[...] See the discussions of additive operators and compound assignment for information on constraints, types, and conversions [...] [...]有关约束,类型和转换的信息,请参见加法运算符和复合赋值的讨论[...]

In case of prefix (unary) operators 如果使用前缀(一元)运算符

[...] The expression ++E is equivalent to (E+=1) [...] [...]表达式++ E等效于(E + = 1)[...]

(The latter is more direct than the former, but the intent with regard to lvalue-ness of the result is the same.) (后者比前者更直接,但是关于结果的左值性的意图是相同的。)

Assignment expression in C is not an lvalue C中的赋值表达式不是左值

An assignment expression has the value of the left operand after the assignment, but is not an lvalue. 赋值表达式具有赋值后的左操作数的值,但不是左值。

As a side note, it is one of the deep fundamental differences between C and C++ languages: C++ is an lvalue-preserving language, while C is an lvalue-discarding language. 附带说明,这是C语言与C ++语言之间深层的根本区别之一:C ++是保留左值的语言,而C是丢弃左值的语言。

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

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