[comp.sys.ibm.pc.programmer] atof

marty@wuphys.wustl.edu (Marty Olevitch) (06/12/90)

Here is something I've just noticed in using the atof() library routine in
Turbo C 2.0. When the following test program is compiled with the "-DWEIRD"
option, the correct answer is printed. However, when "WEIRD" is not
#defined, the error message "scanf : floating point formats not linked" is
printed at runtime. Does the compilation of the sscanf() load in some other
code needed for atof()? If so, how do I get this code loaded without the
dummy call to sscanf() (which in the example is never executed).

Thanks,

Marty Olevitch				Internet: marty@wuphys.wustl.edu
Washington University			UUCP:     uunet!wugate!wuphys!marty
Physics Department, Campus Box 1105	Bitnet:   marty@wuphys.WUSTL
St Louis MO 63130 USA			Tel:      (314) 889-6285

/* atoftest */
#include <stdlib.h>

main()
{
	char s[10];
	double a;
	int yuck;

	sprintf(s," 1.00");

#ifdef WEIRD
	yuck = 0;
	if(yuck == 1)
		sscanf(s, "%f", &a);
#endif
	a = atof(s);
	printf("%f\n", a);

}

jfbruno@rodan.acs.syr.edu (John Bruno) (06/12/90)

In article <1990Jun11.195944.26213@wuphys.wustl.edu> marty@wuphys.UUCP (Marty Olevitch) writes:
 >Here is something I've just noticed in using the atof() library routine in
 >Turbo C 2.0. When the following test program is compiled with the "-DWEIRD"
 >option, the correct answer is printed. However, when "WEIRD" is not
 >#defined, the error message "scanf : floating point formats not linked" is
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 >printed at runtime. Does the compilation of the sscanf() load in some other
 >code needed for atof()? If so, how do I get this code loaded without the
 >dummy call to sscanf() (which in the example is never executed).
 >
 >Thanks,
 >
 >Marty Olevitch				Internet: marty@wuphys.wustl.edu
 >Washington University			UUCP:     uunet!wugate!wuphys!marty
 >Physics Department, Campus Box 1105	Bitnet:   marty@wuphys.WUSTL
 >St Louis MO 63130 USA			Tel:      (314) 889-6285
 >
 > [Short program that calls atof() deleted]

Page 380 Turbo-C User's Guide (Using Floating Point Libraries)
---jb

silver@xrtll.uucp (Hi Ho Silver) (06/16/90)

In article <1990Jun11.195944.26213@wuphys.wustl.edu> marty@wuphys.UUCP (Marty Olevitch) writes:
$Here is something I've just noticed in using the atof() library routine in
$Turbo C 2.0. When the following test program is compiled with the "-DWEIRD"
$option, the correct answer is printed. However, when "WEIRD" is not
$#defined, the error message "scanf : floating point formats not linked" is
$printed at runtime. Does the compilation of the sscanf() load in some other
$code needed for atof()? If so, how do I get this code loaded without the
$dummy call to sscanf() (which in the example is never executed).

   I believe the usual solution to this is to include a line of the form

	exp (1);

in your code (any floating-point math call will do).  This forces the
floating point code to be linked in.
-- 
   /Nikebo \ Nikebo says "Nikebo knows how to post.  Just do it."\silver@xrtll/
  /---------\_____________________________________________________\----------/
 /yunexus!xrtll!silver (L, not 1)\ Hi Ho Silver \   just silver for short   /
/Silver:  Ever Searching for SNTF \  Life sucks. \  someone buy me a BEER! /