nonportable code or incorrect compilers?

Rob Carriere rob at raksha.eng.ohio-state.edu
Sat Jul 9 01:04:05 AEST 1988


In article <133 at daitc.ARPA>, jkrueger at daitc.ARPA (Jonathan Krueger) writes:
> [...] 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
K&R says that ``a*=b'' is eqv to ``a=a*b'' *except* that ``a'' is
evaluated only once.  Sounds like the type cast is not going to be
done => 800 is right.

I don't know about ANSI, I *hope* they changed this; it's horribly
counterintuitive.

Yes, I'm biased; this is what my favorite compiler (Mark Williams C) says.
Rob Carriere



More information about the Comp.std.c mailing list