Path: utzoo!utgpu!water!watmath!julian!uwovax!16012_3045 From: 16012_3045@uwovax.uwo.ca (Paul Gomme) Newsgroups: comp.std.c Subject: Re: nonportable code or incorrect compilers? Message-ID: <430@uwovax.uwo.ca> Date: 27 Jun 88 20:58:35 GMT References: <133@daitc.ARPA> Lines: 25 Organisation: University of Western Ontario, Canada In article <133@daitc.ARPA>, jkrueger@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!