[comp.lang.c] Turbo C Floating Point bug?

dwayne@stratsft.uucp (Dwayne Bailey) (05/24/91)

A client of mine is having a problem with Turbo C 2.0, which I think
is a bug in the compiler, but I'm not positive.  Any light anyone can
shed would be greatly appreciated!

Here is a code fragment which produces the problem:

	/* A bunch of static data defined here */
	static struct stuff={...};

	main()
	{
		float dummy = 2300.0;
		dummy = dummy / 100000.0;
		exit(0);
	}

Simple enough, right?  Well, if it were just this code, it would be.
However, my client is linking in some third party libraries (Window BOSS
and Greenleaf COMM libraries, both compiled for TC.)  The source file which
defines main() also defines some fairly large initialized static data.  What
happens is that the compiler also places the 100000.0 in a static variable
which gets used at runtime.  Unfortunately, at runtime the value placed
in the code points at some other data element, not the expected number.  The
result is random answers or, in this case, Floating point overflow error!

I think the problem is in the code Borland uses to fix up the floating point
routines, based on the presence or absence of the 8087 (both cause the same
problem.)  FYI, I also linked without the windows & comm libraries.  Since
I don't call any of those routines before the error crops up, the unresolved
externals should not be a problem.  Same result, so I don't think you can
blame it on something wierd in the third party stuff.  Also, Turbo C++ 2.0
seems to work fine on the same code.

Any help would be greatly appreciated.

Dwayne Bailey

========================================================================
..!uunet!basfpac!stratsft!dwayne

Dwayne Bailey      +  Strategic Software is ME, so my opinions ARE those
Strategic Software +  of my company!
========================================================================
-- 
========================================================================
..!uunet!basfpac!stratsft!dwayne

Dwayne Bailey      +  Strategic Software is ME, so my opinions ARE those