Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!necntc!linus!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: comp.lang.c Subject: Re: Autoincrement question Message-ID: <2632@mmintl.UUCP> Date: 23 Dec 87 23:37:23 GMT References: <1507@ogcvax.UUCP> <3333@sigi.Colorado.EDU> <7593@eddie.MIT.EDU> <2610@mmintl.UUCP> <2464@killer.UUCP> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT. Lines: 42 In article <2464@killer.UUCP> jfh@killer.UUCP (John Haugh) writes: >In article <2610@mmintl.UUCP>, franka@mmintl.UUCP (Frank Adams) writes: >> Slightly stronger: don't use the target of an assignment operator elsewhere >> in the same expression. Auto-increment and auto-decrement operators are >> assignment operators. > >Way to strong. What you (seem) to be saying is `don't do "a = a + 1"', Oops. Try: don't use the target of an assignment operator elsewhere in the same expression, except in the expression to be assigned to the variable. Don't use the target of auto-increment and auto-decrement operators elsewhere in the same expression. >The expression > > a += a++ + 5 > >is still very legal. I don't think so. It may be that the fine details of expression order evaluation in the ANSI draft make this unambiguous, but since I don't have a copy handy I can't check it. I would *not* trust compilers in general enough to consider it portable, and I think it is in fact legal for compilers to generate code which makes this statement equivalent to "a++" instead of "a += 5" -- the store of the incremented value can be the last code executed for the statement. >> (Actually, you can use such results, provided that the assignment and the >> other use are within different arguments of a comma operator. That is, both >> "f(i) , i++;" and "i++ , f(i);" are unambiguous. But don't do this unless >> (a) you know exactly what you are doing, and (b) you really need to.) > >Given the lack of f() being a macro, f(++i) and f(i++) are both `safe'. Indeed they are; nor did I say otherwise. This was, perhaps, not a very good example. Try f(&i) instead of f(i) in both cases. -- Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108