Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!topaz!ll-xn!mit-amt!mit-eddie!genrad!decvax!tektronix!teklds!copper!stevesu From: stevesu@copper.UUCP (Steve Summit) Newsgroups: net.lang.c Subject: Re: C Compiler bug Message-ID: <500@copper.UUCP> Date: Thu, 24-Jul-86 02:56:39 EDT Article-I.D.: copper.500 Posted: Thu Jul 24 02:56:39 1986 Date-Received: Thu, 24-Jul-86 21:25:23 EDT References: <501@bunny.UUCP> Distribution: net Organization: Tektronix, Inc., Beaverton, OR Lines: 46 Summary: Yes, it's a bug In article <501@bunny.UUCP>, mlr0@bunny.UUCP (Martin Resnick) writes: > Please try this code on your flavor of C compiler... (followed by code demonstrating essentially > i = i/2.5; vs. > i /= 2.5; The answer is absolutely unequivocal on this point. A compiler that does not treat i=i/float and i/=float identically is broken, although many compilers are so broken. This question was discussed to death on the net a year or so ago. The discussion came to a screeching halt, quite unlike most net discussions, when the following article appeared from one dmr@research: > From: dmr@research.UUCP > Newsgroups: net.lang.c > Subject: bug in type conversion > Date: Wed, 4-Jan-84 21:32:17 PST > > Mike O'Brien points out that in the C compilers he has available, the > expression > i *= d; > where i is int and d is double is evaluated in fixed point, and > wonders why. The answer: it is a compiler bug. I fixed it in > (a post V7 version) of the 11 compiler, and it is fixed in the current > System V compiler (by "current" I mean the one I tried; > I don't know what is being shipped at this instant.) > > The manual is reasonably clear and unambiguous on the point, but > it's not surprising that people for search for definition problems when > the compilers are unanimously wrong. > > Dennis Ritchie What the manual says is (K&R page 191): "The behavior of an expression of the form E1 op= E2 may be inferred by taking it as equivalent to E1 = E1 op (E2); however, E1 is evaluated only once." The single evaluation of E1 is the only difference between the two forms; any type casting, including truncation, should be done exactly as if E1 = E1 op (E2) had been performed. Steve Summit tektronix!copper!stevesu