9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] remember when C compiler used to produce working code? i don't!
@ 2004-01-30 22:05 andrey mirtchovski
  2004-01-30 22:29 ` David Presotto
  0 siblings, 1 reply; 17+ messages in thread
From: andrey mirtchovski @ 2004-01-30 22:05 UTC (permalink / raw)
  To: 9fans

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 <u.h>
	#include <libc.h>

	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



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2004-01-31 20:42 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-30 22:05 [9fans] remember when C compiler used to produce working code? i don't! andrey mirtchovski
2004-01-30 22:29 ` David Presotto
2004-01-30 22:40   ` David Presotto
2004-01-31  0:57     ` Bruce Ellis
2004-01-31  1:34       ` boyd, rounin
2004-01-31  1:51       ` Bruce Ellis
2004-01-31  2:15         ` boyd, rounin
2004-01-31  3:13         ` David Presotto
2004-01-31  7:40           ` Bruce Ellis
2004-01-31  9:03             ` andrey mirtchovski
2004-01-31 10:08               ` David Tolpin
2004-01-31 14:19               ` boyd, rounin
2004-01-31 14:57                 ` Bruce Ellis
2004-01-31 17:59             ` Scott Schwartz
2004-01-31 19:23               ` Rob Pike
2004-01-31 19:59                 ` Bruce Ellis
2004-01-31 20:42                 ` Charles Forsyth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).