Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!ll-xn!mit-eddie!killer!jfh From: jfh@killer.UUCP (The Beach Bum) Newsgroups: comp.lang.c Subject: Re: Associativity -- what is it? Message-ID: <3466@killer.UUCP> Date: 24 Feb 88 05:20:14 GMT References: <226@mccc.UUCP> <224@sdrc.UUCP> <234@mccc.UUCP> Reply-To: jfh@killer.UUCP (The Beach Bum) Organization: Big "D" Home for Wayward Hackers Lines: 42 Summary: Postfix ++ explained some more. Not for real programmers. In article <234@mccc.UUCP> pjh@mccc.UUCP (Peter J. Holsberg) writes: [ one explaination down, twenty five more to go ;-) ] >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 This comes from a discussion which I believe was given in the document explaining the implementation of the portable C compiler. Consider ++ in it's two forms as a short-hand notation (don't believe it's true, just consider it. Flames to /dev/null) for: pre-fix: ++ X -> (X = X + 1) post-fix: X ++ -> ((X = X + 1), X - 1) So, the increment gets done, but, the value you get has been `adjusted' if you will. Try this: x = 5; printf ("3 * x ++ = %d\n", 3 * x ++); printf ("now x = %d\n", x); You should get 15 and 4. I suspect you expected 18 or 16 or something like that. [ I believe the context was that the compiler generated the trees using the long-hand, and then hoped to optimize to using increment instructions later. ] - John. -- John F. Haugh II SNAIL: HECI Exploration Co. Inc. UUCP: ...!ihnp4!killer!jfh 11910 Greenville Ave, Suite 600 "You can't threaten us, we're Dallas, TX. 75243 the Oil Company!" (214) 231-0993 Ext 260