nonportable code or incorrect compilers?

Chris Torek chris at mimsy.UUCP
Mon Jun 27 07:32:01 AEST 1988


In article <133 at daitc.ARPA> jkrueger at 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 at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.std.c mailing list