[comp.os.msdos.programmer] Turbo C 2.0 not linking printf f.p. formats

jackg@capella.ucsb.EDU (Jack Greenbaum) (05/06/91)

Within a graphics based application written using Turbo C 2.0 I use 
sprintf("%f ...., but when the program gets there it aborts and prints
the run-time error message "printf : floating point formats not linked". 
The program runs correctly if I remove this line.

I found no documentation on run-time errors, and couldn't find any compiler 
or linker switches that mentioned floating point formats or printf. I'm 
linking all of the required libraries as far as I can tell (cs, maths, 
f87, emu, graphics). 

Just for fun I put a printf("%f\n",1.0) as the first line in the program, 
and got the same error.

Has anyone ever seen this?

-- 
-------------------------------------------------------------------------------
Jack Greenbaum      |UC Santa Barbara
jackg@bears.ucsb.edu|Department of Electrical and Computer Engineering, Box 253
(805) 893-4461      |Santa Barbara, Ca. 93106, USA
-------------------------------------------------------------------------------

afc@mace.cc.purdue.edu (Greg Flint) (05/07/91)

In <11067@hub.ucsb.edu> jackg@capella.ucsb.EDU (Jack Greenbaum) writes:

>Within a graphics based application written using Turbo C 2.0 I use 
>sprintf("%f ...., but when the program gets there it aborts and prints
>the run-time error message "printf : floating point formats not linked". 
>The program runs correctly if I remove this line.

>Just for fun I put a printf("%f\n",1.0) as the first line in the program, 
>and got the same error.

This problem also exists with Turbo C++ version 1.01.

Borland knows about this error and has the following work-around:

	1) add the line "#include <math.h>" to your list of include files.
	2) call some math function to a dummy float variable, e.g., use
		float dummy;
		dummy = cos (1.0);

The floating point libraries will now be loaded for use with the [sf]printf
functions.

I found this out after calling Borland and waiting the usual 20 minutes on
hold -- which brings me to the question:  Is there any place that Borland
posts such known bugs and, if available, work-arounds?   If so, where?
And would someone reading the list be willing to post updates to it to the
net?  Or archive it at an ftp-accessable site?

....Greg Flint (afc@klaatu.cc.purdue.edu)

raymond@math.berkeley.edu (Raymond Chen) (05/07/91)

From the comp.sys.ibm.pc.misc Frequently Asked Questions file:

2.5)  I get the message "floating point formats not linked" when I
      try to run my C program.  Why?

    This is a painfully well-known bug in Turbo C.  Just #include <math.h>
    and stick the line "(void)exp(1.0);" at the start of your main() and
    that should convince the linker to include the floating point formats.
    A patch exists to remedy this bug.

    Patches for Turbo C can be obtained from SIMTEL20, or from LIB 5 of
    the Borland Forum on CompuServe.  There is a Turbo-C mailing list
    on LISTSERV@UCF1VM.BITNET.

    There's a Zortech-C mailing list on uunet!ztc-list-request.

cm315b08@socrates.umd.edu (cm315b08) (05/07/91)

 
References: <11067@hub.ucsb.edu> <7401@mace.cc.purdue.edu>
 
Borland posts things like the 'floating point routines not linked'
in their areas on CI$ and BIX - I'd recommend BIX they have a flat rate, 
and get better tech coverage.
 
The floating point problem really should not be considered a BUG.  The 
linker really cannot know that you need floating point routines in 
a printf (or scanf) statement.  Remember that the format string is just
that, a string and can be built _during_ execution, even in the
statement just before the printf is called.  
 
The way this works is help the optimization.  An even better work around,
suggested by BI is something like:
 
float load_float(float aa, float *bb) {
    float cc ;
    cc = load_float(aa * bb) ;
}
 
Just be sure to _never_ call this.  It seems to load everything that is 
needed from  the floating lib.
- mike
  cm315b08@soctates.umd.edu  (for another week - then)
  75006.3045@compuserve.com
 
.

marc@pinet.aip.org (Marc Wiener) (05/07/91)

In article <7401@mace.cc.purdue.edu> afc@mace.cc.purdue.edu (Greg Flint) writes:

>This problem also exists with Turbo C++ version 1.01.
>
>Borland knows about this error and has the following work-around:
>
>	1) add the line "#include <math.h>" to your list of include files.
>	2) call some math function to a dummy float variable, e.g., use
>		float dummy;
>		dummy = cos (1.0);
>
>The floating point libraries will now be loaded for use with the [sf]printf
>functions.
>
>I found this out after calling Borland and waiting the usual 20 minutes on
>hold -- which brings me to the question:  Is there any place that Borland
>posts such known bugs and, if available, work-arounds?   If so, where?
>And would someone reading the list be willing to post updates to it to the
>net?  Or archive it at an ftp-accessable site?
>
>....Greg Flint (afc@klaatu.cc.purdue.edu)


I found patches on Compuserve several months ago for Turbo C 2.0. They
were posted on Borland's bulletin board. I haven't logged on recntly, but
assume they're still there.

marc
-- 
Marc Wiener                    |    marc@pinet.aip.org
American Institute of Physics  |    marc@aip.bitnet
500 Sunnyside Blvd.            |
Woodbury, NY 11797             |     (516)349-7800