Associativity -- what is it?
The Beach Bum
jfh at killer.UUCP
Wed Feb 24 15:20:14 AEST 1988
In article <234 at mccc.UUCP> pjh at 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
More information about the Comp.lang.c
mailing list