Associativity -- what is it?

Eddie Wyatt edw at IUS1.CS.CMU.EDU
Tue Feb 23 13:16:46 AEST 1988


> 
> 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.

  This really doesn't need a net rely, but ....

  You're having a problem understanding the semantic behind the post
increment instruction.  Think of it this way.

		a = 9 * i++;

is equivalent to

		a = 9 * f(&i);

		int f(x)
		    int *x;
		    {
		    int y;

		    y = *x;
		    *x = *x + 1;
		    return(y);
		    }

and
		a = 9 * ++i;

is equivalent to

		a = 9 * g(&i);

		int g(x)
		    int *x;
		    {
		    int y;

		    *x = *x + 1;
		    y = *x;
		    return(y);
		    }

   Note that i++ evaluates (returns) the value of i before incrementing and
   ++i evaluates (returns) the value of i after incrementing, that's all.

-- 

Eddie Wyatt 				e-mail: edw at ius1.cs.cmu.edu



More information about the Comp.lang.c mailing list