Paramters of type float getting corrupted in Microsoft C 5.1. HELP !!!

brian_helterline brianh at hpcvia.CV.HP.COM
Thu Nov 1 03:34:50 AEST 1990


elee24 at castle.ed.ac.uk (H Bruce) writes:
>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.

[rest of desription deleted]

	One possible source of problems is are you using prototypes and/or
	old style function declarations?  If so, your floats are actually
	being passed as doubles which will mess things up.  As an example:

	int foo(float, float, int);	/* prototype */

	int main()
	{
	  float x,y;
	  int i;
	   .....
	  result = foo( x, y, i );
	}

	int foo( x, y, i )	/* old stype declaration */
	float x,y;		/* floats are really double */
	int i;
	{
	...
	}

	If this is the case, either 1) use ANSI function declaration, or
	2) change your prototype to double (If you generate prototypes
	using the /Zg option with MSC, the prototypes actually come out
	as being doubles!)



More information about the Comp.lang.c mailing list