Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!rpi!crdgw1!crdos1!davidsen From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: is this broken or what? Message-ID: <2033@crdos1.crd.ge.COM> Date: 23 Jan 90 13:36:56 GMT References: <1482@mdbs.UUCP> Reply-To: davidsen@crdos1.crd.ge.com (bill davidsen) Organization: GE Corp R&D Center, Schenectady NY Lines: 34 In article <1482@mdbs.UUCP> wsmith@mdbs.UUCP (Bill Smith) writes: If you didn't see the original post this may be heavily trimmed... | [ original source ] | | unsigned u = 0; | | if (u-- < 4) | printf("yes\n"); | The Data General Aviion 5000 (an 88000 machine) version of GCC converts this | into: | | unsigned u = 0; | | if(--u < 3) .... | This obviously will produce counter-intuitive results. This will generate faster code, due to not keeping the original value of u around, but it looks as if there would be a surprise if the value of u were all ones (~0). To wit: unsigned u; u = ~0; if (u-- < 4) /* this is false, value tested is large # */ if (--u < 3) /* true, value tested is zero */ This *looks like* an unsafen optimization unless the compiler is sure that the value of u is never all ones. -- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "Stupidity, like virtue, is its own reward" -me