[comp.lang.c] Floating Point Formates

timk@xenitec.on.ca (Tim Kuehn) (03/01/90)

I'm working on a program and am having a problem with the atof() function.
Every time I run it with a certain option  turned on I get an error: 
scanf : floating point formats not linked.

The following code sample generates the same error. I've RTFM'd and there's 
not a HINT of anything else that should be brought in in terms of declerations,
etc. 

Anybody have any ideas?

-------code sample here-------
#include <stdio.h>
#include <math.h>
#include <conio.h>
 
char arg[10];
main()
{
clrscr;
printf("start \n");
strcpy(arg, "-f3");
printf("%s \n", arg);
printf("%lf \n", atof(&arg[2]));
}

+-----------------------------------------------------------------------------+
|Timothy D. Kuehn	       			       timk@xenitec.on.ca     |
|TDK Consulting Services			       !watmath!xenitec!timk  |
|871 Victoria St. North, Suite 217A					      |
|Kitchener, Ontario, Canada N2B 3S4 		       (519)-741-3623 	      |
|DOS/Xenix - SW/HW. uC, uP, DBMS. 		       Quality SW Guaranteed  |
+-----------------------------------------------------------------------------+

srt@maui.cs.ucla.edu (Scott Turner) (03/01/90)

In article <1990Feb28.210122.24511@xenitec.on.ca> timk@xenitec.UUCP (Tim Kuehn) writes:
>I'm working on a program and am having a problem with the atof() function.
>Every time I run it with a certain option  turned on I get an error: 
>scanf : floating point formats not linked.

In the future, you should say what compiler you're using, what
machine, etc.  Fortunately this problem is so common that it isn't
necessary.

The problem is that TurboC doesn't link in the floating point lib
unless it thinks it is needed.  And basically TurboC thinks it will be
needed if it sees a floating point function being used.  So to force
TurboC to link in the floating point library, put the pointless line:

	(void) exp(1.0);

somewhere in your code.  That should do it.
 
    Scott R. Turner
    UCLA Computer Science     "It's so bad it's not even wrong"
    Domain: srt@cs.ucla.edu
    UUCP:  ...!{cepu,ihnp4,trwspp,ucbvax}!ucla-cs!srt

mac@idacrd.UUCP (Robert McGwier) (03/02/90)

From article <32397@shemp.CS.UCLA.EDU>, by srt@maui.cs.ucla.edu (Scott Turner):
> In article <1990Feb28.210122.24511@xenitec.on.ca> timk@xenitec.UUCP (Tim Kuehn) writes:
>>I'm working on a program and am having a problem with the atof() function.
>>Every time I run it with a certain option  turned on I get an error: 
>>scanf : floating point formats not linked.
> 
> The problem is that TurboC doesn't link in the floating point lib
> 
> 	(void) exp(1.0);



As I am fond of saying, when you pay $99 for a compiler, what do you
expect? ;->).  I have heard myriad rumors (so what's new?) that Turbo
and Waterloo are (FINALLY) working on an optimizing compiler with
Turbo's front end and Waterloo's output (or some rational combination
thereof), this might be a Turbo C product that I would finally believe
is worth at least $99.  Can anyone lend credence to this rumor?

Bob


-- 
____________________________________________________________________________
    My opinions are my own no matter	|	Robert W. McGwier, N4HY
    who I work for! ;-)			|	CCR, AMSAT, etc.
----------------------------------------------------------------------------

timk@xenitec.on.ca (Tim Kuehn) (03/02/90)

In article <1990Feb28.210122.24511@xenitec.on.ca> timk@xenitec.UUCP (Tim Kuehn) writes:
>I'm working on a program and am having a problem with the atof() function.
>Every time I run it with a certain option  turned on I get an error: 
>scanf : floating point formats not linked.
>
>The following code sample generates the same error. I've RTFM'd and there's 
>not a HINT of anything else that should be brought in in terms of 
> declerations, etc. 
>
>Anybody have any ideas?
>
>-------code sample here-------
>#include <stdio.h>
>#include <math.h>
>#include <conio.h>
> 
>char arg[10];
>main()
>{
>clrscr;
>printf("start \n");
>strcpy(arg, "-f3");
>printf("%s \n", arg);
>printf("%lf \n", atof(&arg[2]));
>}
>

I've gotten a number of replies on this one, and it seems that TC 2.0 
has a problem of being TOO zealous in optimizing spacewise, namely in 
that it optimizes links to the floating point emulation pkg right out 
if it doesn't see something like i9 = exp(1.0); or any other mathematical 
type equation in the program. (Use of the atof() function doesn't 
count as a mathematical function requiring floating point evidently) Thanks 
to all those who wrote, adding the above line (and a double i9 
declaration) fixed the problem quite nicely.

+-----------------------------------------------------------------------------+
|Timothy D. Kuehn	       			       timk@xenitec.on.ca     |
|TDK Consulting Services			       !watmath!xenitec!timk  |
|871 Victoria St. North, Suite 217A					      |
|Kitchener, Ontario, Canada N2B 3S4 		       (519)-741-3623 	      |
|DOS/Xenix - SW/HW. uC, uP, DBMS. 		       Quality SW Guaranteed  |
+-----------------------------------------------------------------------------+