From nobody@FreeBSD.org  Sun Jun 24 17:41:52 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id AF5CC37B405
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 24 Jun 2001 17:41:48 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.3/8.11.3) id f5P0fmR30692;
	Sun, 24 Jun 2001 17:41:48 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200106250041.f5P0fmR30692@freefall.freebsd.org>
Date: Sun, 24 Jun 2001 17:41:48 -0700 (PDT)
From: Tom Garcia <veri2@bigfoot.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: atof incorrect when stdlib.h not #include'd
X-Send-Pr-Version: www-1.0

>Number:         28390
>Category:       bin
>Synopsis:       atof incorrect when stdlib.h not #include'd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jun 24 17:50:01 PDT 2001
>Closed-Date:    Sun Jun 24 23:24:50 PDT 2001
>Last-Modified:  Sun Jun 24 23:27:56 PDT 2001
>Originator:     Tom Garcia
>Release:        4.3-STABLE
>Organization:
HiveMindSystems
>Environment:
FreeBSD queen.nursery.hivemind.org 4.3-STABLE FreeBSD 4.3-STABLE #7: Sun May 20
09:38:10 BST 2001     root@queen.nursery.hivemind.org:/usr/obj/usr/src/sys/QUEEN
  i386     
>Description:
atof returns random odd numbers when stdlib.h not #include'd, otherwise seems to work fine.
>How-To-Repeat:
/* note stdlib.h is not being included */
int main()
{
  printf("%g\n", atof("3.95"));
}

>Fix:
#include <stdlib.h>
>Release-Note:
>Audit-Trail:

From: Gregory Bond <gnb@itga.com.au>
To: Tom Garcia <veri2@bigfoot.com>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/28390: atof incorrect when stdlib.h not #include'd 
Date: Mon, 25 Jun 2001 11:10:31 +1000

 > atof returns random odd numbers when stdlib.h not #include'd, otherwise seems
 >  to work fine.
 
 Calling std library functions (especially those returning anything except 
 "int") without the appropriate header include is a bug in your program, and 
 has nothing to do with FreeBSD or any other OS.  You would get similar errors 
 from a Windows C compiler.
 
 This particular instance is documented in the SYNOPSIS section of the man page
 for atof.
 
 This bug would also have been picked up by compiling with the "-Wall" flag.
 
 This PR can be closed.
 
 
State-Changed-From-To: open->closed 
State-Changed-By: roam 
State-Changed-When: Sun Jun 24 23:24:50 PDT 2001 
State-Changed-Why:  
Many, many functions depend on some header file or other to be included 
in order to function properly.  This has been well-documented in both 
the C standard, and the respective manpages. 

In this particular case, atof(3) fails simply because if there is no 
prototype, the compiler assumes that the function returns int. 
You might explicitly declare atof() to return double, or, much better, 
you should include the appropriate header files. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28390 
>Unformatted:
