Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site cubsvax.UUCP Path: utzoo!watmath!clyde!burl!hou3c!hocda!houxm!hogpc!houti!ariel!vax135!floyd!cmcl2!rocky2!cubsvax!peters From: peters@cubsvax.UUCP Newsgroups: net.lang.c,net.bugs.4bsd Subject: Re: i = i * f vs. i *= f Message-ID: <205@cubsvax.UUCP> Date: Sun, 15-Apr-84 15:12:31 EST Article-I.D.: cubsvax.205 Posted: Sun Apr 15 15:12:31 1984 Date-Received: Tue, 17-Apr-84 08:00:26 EST References: <866@elsie.UUCP> Organization: Columbia Univ Biology, New York City Lines: 28 Looks like you found a real bug! on the 4.1bsd compiler, the following program -- which compares i = i / f with i /= f -- gives the results indicated. Obviously, the problem is that when the compiler encounters "int op= float;" it casts the float to an int before doing the evaluation, instead of promoting the int to a float, then casting the result. According to K&R, p191, the two expressions "may be taken as equivalent" (slight paraphrase), which is *very* misleading if this isn't a bug. They then say, "... however, [for "op=" ] E1 [left-hand side] is evaluated only once." This is opaque to me. Can someone explain it? I. e., does that mean it's not a bug? It's egregious [look it up!] in any case. main() { int i; i = 100; i = i / 3.3; printf("i = i/3.3 gives: %d\n", i); /* gives 30, as expected */ i = 100; i /= 3.3; printf("i /= 3.3 gives: %d\n", i); /* gives 33!!!! */ } {philabs,cmcl2!rocky2}!cubsvax!peters Peter S. Shenkin Dept of Biol. Sci.; Columbia Univ.; New York, N. Y. 10027; 212-280-5517 "In accordance with the recent proclivity for clever mottos, this is mine."