Nasty bug

Michael Meissner meissner at osf.org
Sat Sep 1 00:32:38 AEST 1990


In article <6441 at wolfen.cc.uow.oz> pejn at wolfen.cc.uow.oz (Paul Nulsen)
writes:

| wallace at ynotme.enet.dec.com (Ray Wallace) writes:
| 
| >In article <0093BF08.7F3834E0 at rigel.efd.lth.se>, e89hse at rigel.efd.lth.se
| >writes... 
| >>... Therefore &f is a ptr to double rather than a
| >>ptr to float as one would expect looking at the declartion.
| 
| >Sounds like a compiler bug to me.
| 
| I am not sure what the standard says, but this is definitely not a compiler
| bug. With old K&R style declarations the compiler does not know the type of
| a function argument until it sees the function definition. The function can
| be invoked before the definition is known, and hence before the argument
| types are known. In the case of floating point numbers, to avoid the
| problems this creates the approach adopted was to promote all floating point
| types to the common type of double. With ANSI style declarations this is no
| longer necessary.

I would still argue it's a compiler bug, even in K&R-I.  If you said
float, what the compiler should do is realize that a double was
passed, take said double, convert it to float, and store it somewhere
(including back on the stack where it was passed).  Then any
references are still float, and not double.  You do have a conversion
from double to float in the procedure prologue.  The same conversion
goes for char and short parameters, though you can usually fake the
address (and using the little endian false belief, you don't have to
do that).  The one good thing you could say about IBM floating point
format, is that the float and double formats were the same, and you
could ignore the bottom bits.

ANSI requires the above behavior in the absence of prototypes.
--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?



More information about the Comp.lang.c mailing list