Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!srhqla!demott!kdq From: kdq@demott.COM (Kevin D. Quitt) Newsgroups: comp.lang.c Subject: Re: Is something wrong with the compiler ? Message-ID: <645@demott.COM> Date: 2 Oct 90 21:42:05 GMT References: <1895@tuvie> Reply-To: kdq@demott.COM (Kevin D. Quitt) Organization: DeMott Electronics Co., Van Nuys CA Lines: 27 In article <1895@tuvie> hp@vmars.tuwien.ac.at (Peter Holzer) writes: > >Expression: Value: >(a = ~0) (int) ~0 >(unsigned)(a = ~0) (unsigned) ~0 >((unsigned)(a = ~0) >> 1) (unsigned) MAXINT >(int)((unsigned)(a = ~0) >> 1) (int) MAXINT >a = (int)((unsigned)(a = ~0) >> 1) (int) MAXINT > >Anything wrong with my reasoning? Yes. Undefined order or assignment means undefined. It is perfectly legitimate for the (a = ~0) assignment to actually take place after the a = (int)((unsigned)(a = ~0) >> 1) assignment. That's what undefined order means. I agree that a proper compiler "knows" that the former is unnecessary, and can/will be optimized away, but a compiler that isn't that smart *isn't* broken (according to the spec). -- _ Kevin D. Quitt demott!kdq kdq@demott.com DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266 VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last 96.37% of all statistics are made up.