Increment Operators vs. Precedence
Peter da Silva
peter at ficc.ferranti.com
Fri Mar 8 09:44:39 AEST 1991
In article <THOMSON.91Mar5173421 at zazen.macc.wisc.edu> thomson at zazen.macc.wisc.edu (Don Thomson) writes:
> The example on the board is y = x++, and I explain that x gets
> assigned to y before x is incremented.
So you used loose terminology. And confused them. What you meant was that
the value of x as it was before incrementing is assigned to y. X may in
fact have been assigned first, as in:
y[x] = x++
which has an undefined result.
> So the dilemma is how to explain that
> precedence is not the issue here, that the order of operations is tied to the
> definition of prefix versus postfix increment operators.
Don't explain that, because it's not in fact true. If you leave them
believing that they will believe the expression I gave above has a defined
result. Explain it in terms of expressions, their values, and side effects:
"x++" is an expression that returns the value of x as it was
before incrementing, and as a side effect increments x.
Precedence is not the issue, but neither is the order of operations.
--
Peter da Silva. `-_-' peter at ferranti.com
+1 713 274 5180. 'U` "Have you hugged your wolf today?"
More information about the Comp.lang.c
mailing list