Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!bagate!asi!disc.dla.mil!dsacg3.dsac.dla.mil!nfs1675 From: nfs1675@dsacg3.dsac.dla.mil (Michael S Figg) Newsgroups: comp.sys.amiga.programmer Subject: Re: Compiler code (was a flame fest) (now a lesser flame fest) Summary: Bad coding Message-ID: <3165@dsacg3.dsac.dla.mil> Date: 23 Apr 91 13:58:31 GMT References: <1991Apr17.180342.25312@engin.umich.edu> <91112.093750GHGAQZ4@cc1.kuleuven.ac.be> Organization: Defense Logistics Agency Systems Automation Center, Columbus Lines: 46 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 I've tried this on 3 different machines and only proved that this is poor (real poor) coding practice. Including the above test, 6 out of the 8 permutations had three different answers. Results are as follow: Jorrit Gould 9050 ATT 3B2 PC (MSC 6.0) (n--)*(n++) -> 12 20 12 16 (n++)*(n--) -> 20 12 20 16 (--n)*(++n) -> 16 16 12 16 (++n)*(--n) -> 16 16 20 16 (--n)*(n++) -> 12 16 9 9 (++n)*(n--) -> 20 16 25 25 (n--)*(++n) -> 16 20 16 25 (n++)*(--n) -> 16 12 16 9 Since I'm not at home, I haven't had the chance to try this on the Amiga (SAS/C 5.1), but it would probably be as unpredictable as the other 4 machines. ---Mike, -- -------- o A herd of bagels | Michael Figg DSAC-FSD | | -- oo o o escaping from a deli. | DLA Systems Automation Center | | -- ooo oo Looking for Lox in | Cols, Ohio mfigg@dsac.dla.mil -------- o o all the wrong places | CIS: 73777,360