Post Increment with respect to Sequence Points

女生的网名这么多〃 提交于 2019-11-27 04:57:15

问题


When does the post increment operator affect the increment? I have come across two opinions:

1) From http://gd.tuwien.ac.at/languages/c/programming-bbrown/c_015.htm:

POST means do the operation after any assignment operation.

2) Closer home, an answer on SO(albeit on C++) says:

... that delays the increment until the end of the expression (next sequence point).

So does the post increment operation...

A) wait until a sequence point is reached or

B) happen post an assignment operator or

C) happen anytime before the sequence point?


回答1:


The correct interpretation is C, ie. the increment happens sometime before the next sequence point, specifically the C standard (C99, 6.5.2.4, 2) says this:

The side effect of updating the stored value of the operand shall occur between the previous and the next sequence point.

Full paragraph quotation:

The result of the postfix ++ operator is the value of the operand. After the result is obtained, the value of the operand is incremented. (That is, the value 1 of the appropriate type is added to it.) See the discussions of additive operators and compound assignment for information on constraints, types, and conversions and the effects of operations on pointers. The side effect of updating the stored value of the operand shall occur between the previous and the next sequence point.




回答2:


The post increment operation always occurs before the next sequence point irrespective of the expression where the increment operator is being used. See this link for more info http://en.wikipedia.org/wiki/Sequence_point



来源:https://stackoverflow.com/questions/4865599/post-increment-with-respect-to-sequence-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!