nonportable code or incorrect compilers?

Paul Gomme 16012_3045 at uwovax.uwo.ca
Tue Jun 28 06:58:35 AEST 1988


In article <133 at daitc.ARPA>, jkrueger at daitc.ARPA (Jonathan Krueger) writes:
> Here's a question of portability and language standards that came up in
> a real life program.  According to K&R or ANSI, predict the output of
> the following code:
> 
> #define	DEFCONST	1.05
> main()
> {
> 	int	count = 800;
> 
> 	printf("count is %d, ", count);
> 	count *= DEFCONST;
> 	printf("now %d\n", count);
> }
> 
> My prediction, based on K&R, was the output:
> 	count is 800, now 839
> 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?

	Just to stir things up a little, under VAX/VMS, I get an answer
of 839; Turbo C gives an answer of 840!



More information about the Comp.std.c mailing list