(Postincrement/Postdecrement): Small clarification.
This commit is contained in:
parent
ae13d4a5de
commit
2f8e7ba6d5
21
c.texi
21
c.texi
|
@ -2803,9 +2803,14 @@ prints lines containing 5, again 5, and 6. The expression @code{i++}
|
||||||
has the value 5, which is the value of @code{i} at the time,
|
has the value 5, which is the value of @code{i} at the time,
|
||||||
but it increments @code{i} from 5 to 6 just a little later.
|
but it increments @code{i} from 5 to 6 just a little later.
|
||||||
|
|
||||||
How much later is ``just a little later''? That is flexible. The
|
How much later is ``just a little later''? The compiler has some
|
||||||
increment has to happen by the next @dfn{sequence point}. In simple cases,
|
flexibility in deciding that. The rule is that the increment has to
|
||||||
that means by the end of the statement. @xref{Sequence Points}.
|
happen by the next @dfn{sequence point}; in simple cases, that means
|
||||||
|
by the end of the statement. @xref{Sequence Points}.
|
||||||
|
|
||||||
|
Regardless of precisely where the compiled code increments the value
|
||||||
|
of @code{i}, the crucial thing is that the value of @code{i++} is the
|
||||||
|
value that @code{i} has @emph{before} incrementing it.
|
||||||
|
|
||||||
If a unary operator precedes a postincrement or postincrement expression,
|
If a unary operator precedes a postincrement or postincrement expression,
|
||||||
the increment nests inside:
|
the increment nests inside:
|
||||||
|
@ -2817,11 +2822,11 @@ the increment nests inside:
|
||||||
That's the only order that makes sense; @code{-a} is not an lvalue, so
|
That's the only order that makes sense; @code{-a} is not an lvalue, so
|
||||||
it can't be incremented.
|
it can't be incremented.
|
||||||
|
|
||||||
The most common use of postincrement is with arrays. Here's
|
The most common use of postincrement is with arrays. Here's an
|
||||||
an example of using postincrement to access one element of an
|
example of using postincrement to access one element of an array and
|
||||||
array and advance the index for the next access. Compare
|
advance the index for the next access. Compare this with the example
|
||||||
this with the example @code{avg_of_double}, which is almost
|
@code{avg_of_double} (@pxref{Array Example}), which is almost the same
|
||||||
the same but doesn't use postincrement (@pxref{Array Example}).
|
but doesn't use postincrement.
|
||||||
|
|
||||||
@example
|
@example
|
||||||
double
|
double
|
||||||
|
|
Loading…
Reference in New Issue