Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!tandem!zorch!xanthian From: xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan) Newsgroups: comp.sys.amiga.programmer Subject: Side Effects == Rattlesnakes -- watch out for them Re: Compiler code (was a flame fest) (now a lesser flame fest) Message-ID: <1991May4.061257.14959@zorch.SF-Bay.ORG> Date: 4 May 91 06:12:57 GMT References: <24503@well.sf.ca.us> Organization: SF-Bay Public-Access Unix Lines: 29 farren@well.sf.ca.us (Mike Farren) writes: > jsmoller@jsmami.UUCP (Jesper Steen Moller) writes: >> result=func1()+func2(); >> Question: Can't you rely on func1() being called before func2()??? >> Really not? > Nope. Really not. There is no guarantee at all that the compiler will > call func1 first - the only guarantee is that both functions will have > been called before the add takes place :-) >> Oh, by the way: func(a++) Is "a" increased before or after the >> function call. I think I once read in K&R that it was undefined, but >> I might be mistaken. > Nope, not undefined. a is evaluated, and passed to the function when > it is called, and then is incremented. This *is* guaranteed. Which still leaves the wide open "gotcha" that if func() modifies "a" by a side effect during execution, all bets are off as to whether the pre-call or the post-call value is what gets incremented and stored back in "a". Best rule for C side effects -- don't. Kent, the man from xanth.