From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@cse.psu.edu From: andrey mirtchovski MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] remember when C compiler used to produce working code? i don't! Date: Fri, 30 Jan 2004 15:05:43 -0700 Topicbox-Message-UUID: c83a9aa6-eacc-11e9-9e20-41e7f4b1d025 I got bitten by this one pretty hard today, took me the better part of the day to find out... The 'elasticity *= ratio' code comes from the XScreensaver distribution and was written sometime in 1997, so presumably this has been working since then (and braking when compiled with 8c?). In Plan 9 the following code produces 800/0: plan9-2% cat t.c #include #include main() { long elasticity = 8000L; double ratio = 0.1; /* this is fine */ elasticity = (long)(((double)elasticity)*ratio); print("%ld\n", elasticity); /* this breaks with 8c */ elasticity *= ratio; print("%ld\n", elasticity); } plan9-2% 8c t.c; 8l t.8 plan9-2% 8.out 800 0 plan9-2% Its (almost) identical lunix counterpart, when compiled with gcc 3.2, produces 800/80: mirtchov@fbsd$ cat t.c main() { long elasticity = 8000L; double ratio = 0.1; /* this is fine */ elasticity = (long)(((float)elasticity)*ratio); printf("%ld\n", elasticity); /* this if fine with gcc 3.2 */ elasticity *= ratio; printf("%ld\n", elasticity); } mirtchov@fbsd$ gcc t.c mirtchov@fbsd$ ./a.out 800 80 mirtchov@fbsd$ Not looking to assign any blame, just letting you know... andrey