Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!hao!gatech!udel!princeton!mccc!pjh From: pjh@mccc.UUCP (Peter J. Holsberg) Newsgroups: comp.lang.c Subject: Re: Associativity -- what is it? Message-ID: <240@mccc.UUCP> Date: 25 Feb 88 17:57:19 GMT References: <226@mccc.UUCP> <224@sdrc.UUCP> <234@mccc.UUCP> <230@sdrc.UUCP> Reply-To: pjh@mccc.UUCP (Peter J. Holsberg) Organization: The College on the Other Side of US Route 1 Lines: 47 In article <230@sdrc.UUCP> scjones@sdrc.UUCP (Larry Jones) writes: |In article <234@mccc.UUCP>, pjh@mccc.UUCP (Peter J. Holsberg) writes: |> In article <224@sdrc.UUCP> scjones@sdrc.UUCP (Larry Jones) writes: |> |In article <226@mccc.UUCP>, pjh@mccc.UUCP (Peter J. Holsberg) writes: |> |> |> |> 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? | |The result of i++ is the value of i. In addition, i gets incremented. You |can think of i++ as being like inc(&i) where inc() is defined as: | | int inc(ip) | int *ip; | { | int j = *i; | *i = *i + 1; | return j; | } | |So, it's not the ++ operator that's defered, it's the side effect of the ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |incrementation. You should also be aware that the incrementation can be |defered for a long time - it may not happen until after the assignment. |That's why i = i++ + 2; has no defined value -- you don't know whether the |incrementation is done before or after the assignment. | ???? Then what does the ++ operator-sans-side effect actually do??? It looks like it does nothing. -- Peter Holsberg UUCP: {rutgers!}princeton!mccc!pjh Technology Division CompuServe: 70240,334 Mercer College GEnie: PJHOLSBERG Trenton, NJ 08690 Voice: 1-609-586-4800