integer *= float

Ed Hall edhall at randvax.ARPA
Sun Jan 8 05:26:26 AEST 1984


-------------------------------------------------
>> It just goes to show, always type your code explicitly.
>> Shun implicit declarations or type conversions -- they'll get you
>> in the end.
>>                                          Steve Summit
>>                                         tektronix!tekmdp!stevesu

A bit of a non sequitur here.  Explicit casts have no effect on the
bug.  Even calling a double-to-long conversion function, where one
exists, can't make op= behave (the syntax doesn' allow it).  All you
can do is avoid integer op= float altogether.

The bug is an understandable one for a compiler writer.  This is
the only case where conversion operators can't easily be inserted
before code generation.  So, when floating-point is added to the
compiler it is easy for this one to fall through the cracks.

The small number of C programs that use floating-point are often
written by people who aren't likely to use the more un-fortran-like
deatures of C such as asignment ops.  Thus, the bug itself goes
relatively unnoticed.

It should be noted that this bug affects /= and -= as well as *=
operators.  Whether += has problems depends upon whether the machine
rounds or truncates.  In the latter case it makes little difference
whether truncation occurs before or after the addition.  (Why is
this not true for subtraction? --exercise for the reader.)

		-Ed Hall
		decvax!randvax!edhall



More information about the Comp.lang.c mailing list