Associativity -- what is it?

Peter J. Holsberg pjh at mccc.UUCP
Tue Feb 23 04:55:39 AEST 1988


In article <224 at sdrc.UUCP> scjones at sdrc.UUCP (Larry Jones) writes:
|In article <226 at mccc.UUCP>, pjh at mccc.UUCP (Peter J. Holsberg) writes:
|> 
|> I find that associativity is a *very* difficult thing for me to explain,
|> undoubtedly because I don't understand it!  Would someone come to my
|> rescue?  Here's an example (assume that everything's been declared
|> correctly):
|> 
|> 	x = 3 * i ++;
|> 
|> Book says that ++ has a higher precedence than *, and that ++
|> associates from R->L.  That makes me think that ++ should be applied
|> first, but I know it isn't.  But ????
|
|But ++ IS applied first!  The key point here is that the RESULT of postfix
                                                          ^^^^^^^^^^^^^^^^^
|++ is the value BEFORE incrementation, not that postfix ++ is somehow deferred
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|until later.

Well, that still leaves me confused.  If i has the value 7, it is 7 that
is added to 3, so it seems to be that the ++ *is* deferred until later. 
Also, ++ has higher precedence than +, so why is the incrementation
delayed until after the current value of i is used?
 
I think we're getting close, though.  :-)  Thanks for the help.

-- 
Peter Holsberg                  UUCP: {rutgers!}princeton!mccc!pjh
Technology Division             CompuServe: 70240,334
Mercer College                  GEnie: PJHOLSBERG
Trenton, NJ 08690               Voice: 1-609-586-4800



More information about the Comp.lang.c mailing list