9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: andrey mirtchovski <mirtchov@cpsc.ucalgary.ca>
To: 9fans@cse.psu.edu
Subject: [9fans] remember when C compiler used to produce working code? i don't!
Date: Fri, 30 Jan 2004 15:05:43 -0700	[thread overview]
Message-ID: <d45fb131231fd5a3515e0f7518a6568a@plan9.ucalgary.ca> (raw)

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



             reply	other threads:[~2004-01-30 22:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-30 22:05 andrey mirtchovski [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d45fb131231fd5a3515e0f7518a6568a@plan9.ucalgary.ca \
    --to=mirtchov@cpsc.ucalgary.ca \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).