Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mandrill!gatech!uflorida!umd5!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.std.c
Subject: Re: nonportable code or incorrect compilers?
Keywords: portable language standard
Message-ID: <12154@mimsy.UUCP>
Date: 26 Jun 88 21:32:01 GMT
References: <133@daitc.ARPA>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 31

In article <133@daitc.ARPA> jkrueger@daitc.ARPA (Jonathan Krueger) writes:
[only the following three lines are needed]
>#define	DEFCONST	1.05
>	int	count = 800;
>	count *= DEFCONST;

The correct result is 840 (or something nearby, such as 839, depending
on roundoff error).

>Indeed, the Pyramid 98x produces exactly this output.
>But your mileage may vary.  4.2BSD VAX, Gould, and Sun-3 produce output:
>	count is 800, now 800
>Which brings me to the question: is this code non-portable, or do
>three out of four compilers surveyed fail to correctly implement K&R?

Three out of four compilers surveyed failed to correctly implement K&R.

The bug is an easy one to commit in PCC.  It was fixed some time ago
(I think it was fixed in 4.3BSD).  Try also

	f() {
		unsigned *a();
		int b();

		*a() %= b();
	}

and see whether the code generated is correct.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris