Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ark1!oasys!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Nasty bug Message-ID: <26350@mimsy.umd.edu> Date: 4 Sep 90 16:05:33 GMT References: <2020@engage.enet.dec.com> <6441@wolfen.cc.uow.oz> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 37 In article richard@iesd.auc.dk (Richard Flamsholt S0rensen) writes: > Nope. ANSI states, that floats remain floats unless the expression >contains more precise types, that is long double or double, in which >case the float in converted. This is *almost* right. The ANSI C standard does not say that a compiler cannot do `float f = 0.1; f += f;' as `convert f to double; add double to double; convert result to float', but it does give the compiler the option of doing it as `add float to float'. (This is similar to the fact that the standard does not require a compiler to, say, not insert delay loops after every few instructions ---except that the delay loops would be better proof of a stupid compiler! In other words, the standard does not, and cannot, outlaw bad code generation.) >Therefore, if the float is the only parameter to a function it is >*not* converted to a double in the expression, regardless of how the >function was declared. This, however, is almost completely wrong. When an actual parameter has type float, the value is not altered *only* when a function prototype is in scope and the corresponding formal parameter also has type float. If no prototype is in scope, or if the prototype has run into a `...', the value is widened. This is easily demonstrated by noting that float f; double d; ... (void) printf("%f %f\n", f, d); is correct: we do not need `%lf' to print d. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris