Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!mrd@sun.mcs.clarkson.EDU From: mrd@sun.mcs.clarkson.EDU (Michael R. DeCorte) Newsgroups: comp.lang.c Subject: Autoincrement question Message-ID: <10898@brl-adm.ARPA> Date: 18 Dec 87 08:52:17 GMT Sender: news@brl-adm.ARPA Lines: 42 From: John Haugh The expression a += a++ + 5 is still very legal. Sorry but this is not legal. Look at the original expression with the a's subscripted and assume that a = 10 for the discussion. a += a++ + 5 1 2 The right hand side will evaluate to 15, no problem. The += will Take a's current value (5) and add 15 to it yielding 20, no problem. Now the problem. a2 must be incremented but you don't know if it will occur before the assignment to a1 or after. If it occurs before then this is equivelent to t = a + a + 5; a++; a = t; a will equal 20. If the increment occurs after the assignment then you have t = a + a + 5; a = t; a++; a will equal 21. (the a=t here is not needed but just put in for clarity and this is the code that the compiler will generate) The statment that you should NEVER have an expression where a single variable has more than one post(pre)-increment(decrement)'s is correct. You should also NEVER post(pre)-increment(decrement) a variable that occurs on both side of the equation. Michael DeCorte mrd@clutx.clarkson.edu mrd@clutx.bitnet