Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!pa.dec.com!bacchus!mwm From: mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) Newsgroups: comp.sys.amiga.programmer Subject: Re: Compiler code (was a flame fest) (now a lesser flame fest) Message-ID: Date: 29 Apr 91 19:22:02 GMT References: Sender: news@pa.dec.com (News) Followup-To: comp.sys.amiga.programmer Organization: Missionaria Phonibalonica Lines: 40 In-Reply-To: jsmoller@jsmami.UUCP's message of 26 Apr 91 07:15:22 GMT In article jsmoller@jsmami.UUCP (Jesper Steen Moller) writes: ---- FICTIVE CODE START ---- int func1(void); int func2(void); int result; result=func1()+func2(); ---- FICTIVE CODE END ---- Question: Can't you rely on func1() being called before func2()??? Really not? Really not. > ++a + ++a > > If a is 1, the result can be 2 + 2 or 2 + 3 or 3 + 2 and at the end 'a' > can be either 3 or 4 depending on how the compiler was designed. DO NOT > DEPEND ON ANY PARTICULAR SIDE EFFECT WITH ++ or -- ACTING ON THE SAME > VARIABLE MORE THAN ONCE IN ANY EXPRESSION, EVER, OR YOUR CODE WILL BE > UNPORTABLE EVEN ACROSS REVISIONS OF THE SAME COMPILER! 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. I'm not sure what K&R said, but ANSI says that the arguments are evaluated, then there's a sequence point, then the call happen. At sequence points, all side effects must have taken place, so a will have been incremented before the call.