Associativity -- what is it?

0732 al at gtx.com
Sat Feb 27 01:44:19 AEST 1988


In article <4140 at ptsfa.UUCP> dmt at ptsfa.UUCP (Dave Turner) writes:
 
>I've always found it to be useful to look at ++x and x++ and say:
>
>	x++	use the present value of x in any other expressions in this
>		statement before incrementing x.

I hate to keep beating this horse, but the above statement is false.
just see K&R p. 50.

The problem the original questioner had [ essentially, "in a+b++ why
does the addition appear to be done before the incrementation when the
incrementation has higher priority?"] is just due to a confusion of
syntax with semantics.  syntactically, the ++ has higher priority and
IS "applied" first.  However, the semantics of applying ++ are defined
in such a way as to defer the side effect.  (exactly how long to defer
the side effect is not well defined.)

    ----------------------------------------------------------------------
   | Alan Filipski, GTX Corp, 2501 W. Dunlap, Phoenix, Arizona 85021, USA |
   | {ihnp4,cbosgd,decvax,hplabs,amdahl}!sun!sunburn!gtx!al (602)870-1696 |
    ----------------------------------------------------------------------



More information about the Comp.lang.c mailing list