[comp.lang.c] Problem with float in TurboC 1.0?

larryg@nyssa.CS.ORST.EDU (Larry Gilbert) (10/09/89)

I am trying to get some third-party C source to compile under TurboC version
1.0 [sic].  It does a lot of passing of type 'float' parameters, and I'm
finding that a lot of times, when there is an attempt to pass a float
parameter to a function, it mysteriously gets reset to 0.0.  Can anyone give
me a clue as to what is going on, or what I should look out for?  Thanks.

--
Larry Gilbert, larryg@jacobs.cs.orst.edu

swh@hpcupt1.HP.COM (Steve Harrold) (10/09/89)

Re: floats with Turbo C

Be careful when passing "float" types with any ANSI-conformant compiler.

When you compile a function that is declared as expecting a "float" parameter,
the ANSI compiler will generate code to extract a "float" value from the stack.

If, in a separate compilation, you have a program that references the function,
AND you neglect to explicitly provide a prototype statement that declares the
"float" specification, the compiler will generate code the "old fashioned"
way and insert a "double" into the stack.  Because this parameter type
mismatch is not (generally) detected by the linker you use, the run time
execution will be unpredictable (because "double"s are placed into the stack,
but are being extracted as "single"s!!).

Hope this provides the clue you need.