Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!mcsun!hp4nl!cbmnlux!cbmehq!cbmdeo!jsmami!jsmoller From: jsmoller@jsmami.UUCP (Jesper Steen Moller) Newsgroups: comp.sys.amiga.programmer Subject: Re: Compiler code (was a flame fest) (now a lesser flame fest) Message-ID: Date: 26 Apr 91 07:15:22 GMT Followup-To: comp.sys.amiga.programmer Organization: Danish SofTech Lines: 70 In article dillon@overload.Berkeley.CA.US (Matthew Dillon) writes: > > In article <91112.093750GHGAQZ4@cc1.kuleuven.ac.be> GHGAQZ4@cc1.kuleuven.ac.be writes: > >> Nope. ++ and -- are unary operators of the highest precedence. The only > >>difference between ++x and x++ is the value they assume, the order of eval- > >>uation follows standard C precedence.. > > > >I think you are wrong. Look at the following results : > >I have tried this with our mainframe compiler : > > int n=4; > > > > (n--)*(n++) -> 12 > > (n++)*(n--) -> 20 > > (--n)*(++n) -> 16 > > (++n)*(--n) -> 16 > > (--n)*(n++) -> 12 > > (++n)*(n--) -> 20 > > (n--)*(++n) -> 16 > > (n++)*(--n) -> 16 > > > > Jorrit Tyberghein > > Obviously the compiler is going to do it a certain way, but that > represents only the particular implementation of the compiler used. If > you have an expression: > > exp1 * exp2 > > There is NO GUARENTEE on the order of evaluation... exp1 before exp2 or > exp2 before exp1, no matter *what* exp1 and exp2 contains. Period. Aha! A friend of mine asked if you could rely on the following: ---- 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? > ++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! H*ll to debug, anyway... min() and max() rules!!! 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. > -Matt Greets, Jesper -- __ Jesper Steen Moller /// VOICE: +45 31 62 46 45 Maglemosevej 52 __ /// USENET: cbmehq!cbmdeo!jsmami!jsmoller DK-2920 Charl \\\/// FIDONET: 2:231/84.45 Denmark \XX/