Float parameters "corrupted" - solution found !!!!!

H Bruce elee24 at castle.ed.ac.uk
Mon Nov 5 21:56:37 AEST 1990


I posted this question recently:

> I am having a problem with Microsoft C (V 5.1).
> 
> When I pass a parameter of type float (by value) to a function, by the time
> it is read from the stack by the function it is corrupted.
> The corrupted value is something very small (eg X.XXXXe-XXX) and varies
> depending on the parameter.

I forgot to state in my original posting was that I declared ANSI style
prototypes for external functions. 
I also did not mention that this was not a repeatable "bug".
By this I mean that each time the program was complied you could not
guarantee that the problem would appear.

I wish to thank everyone that replied to this question.
The net really helped me out on this one - I was getting desperate.

In fact many people had suffered the same problem in past.
I always find this very re-assuring !
It would appear that the root of the problem is that the compiler
sometimes (unexpectedly ?) converts a floats parameter to a double.

The most common solution I received was to declare the external function
prototypes in ANSI format. 
As discussed above this did not solve the problem.
However all this talk of float a doubles led me to fiddle with parameter
types. I appear to have fixed the problem with the following:

1. Leave external function with the function float parameter alone.
2. In the external function prototype section of the calling module, declare the
   float parameter as a double.

Can anyone comment and tell me why this has worked ?


Thanks again to all who replied,

Henry.



More information about the Comp.lang.c mailing list