Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site hcrvx1.UUCP Path: utzoo!hcrvax!hcrvx1!aam From: aam@hcrvx1.UUCP (Allen McIntosh) Newsgroups: net.lang.c,net.bugs.usg Subject: i *= 0.5 revisited Message-ID: <974@hcrvx1.UUCP> Date: Wed, 17-Oct-84 17:11:13 EDT Article-I.D.: hcrvx1.974 Posted: Wed Oct 17 17:11:13 1984 Date-Received: Sat, 20-Oct-84 01:19:17 EDT Organization: Human Computing Resources, Toronto Lines: 25 The System 5.2 C compiler for the VAX contains a bug "fix" for the infamous "i *= 0.5" bug discussed recently on the net. Alas, the fix introduces yet another bug. To demonstrate it, try running the following C program: int a[2] = { 2, 9 }; main() { int i; i = 0; a[i++] *= 0.5; printf("i = %d, a[0] = %d, a[1] = %d\n", i, a[0], a[1]); if( i != 1 || a[0] != 1 || a[2] != 9 ) printf("Wrong. Correct answer is i=1, a[0]=1, a[1]=9\n"); } On our VAX running System 5.2, the output looks like this: i = 2, a[0] = 2, a[1] = 1 Wrong. Correct answer is i=1, a[0]=1, a[1]=9 The problem is the routine assign() added to local.c to fix the original problem. It blindly makes a copy of the left subtree of the "*=" without checking for side effects. Does anyone have a working fix for this that does not degrade code quality?