i = i * f *vs* i *= f (Not a bug) (Yes, a bug!)
Peter S. Shenkin
peters at cubsvax.UUCP
Wed Apr 18 02:30:32 AEST 1984
Re: Bennett Todd's assertion that the problem is not a bug:
cf K&R p 41: "In general, if... a "binary operator" has operands of different
types, the "lower" type is *promoted* to the "higher" before the
operation proceeds....
This, coupled with their assertion elsewhere that x = x op y "may be taken
as equivalent" (or words to that effect) to x op= y, would seem to indicate
that i *= f and i = i * f should evaluate the expression with i and f as
floats, then cast the result to int. In any case, they should evaluate
the expression the same way! If you disagree, quote me chapter and verse.
Net effect: it's a bug!
Moral: beware implicit type conversions, since they may not do what K&R
says they do.
By the way, I'd be curious to see the results of the program on other
compilers.
{philabs,cmcl2!rocky2}!cubsvax!peters Peter S. Shenkin
Dept of Biol. Sci.; Columbia Univ.; New York, N. Y. 10027; 212-280-5517
"In accordance with the recent proclivity for clever mottos, this is mine."
More information about the Comp.lang.c
mailing list