delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/06/11:06:31

Date: Mon, 6 Sep 1999 09:43:22 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Berti Drost <Berti DOT drost AT gmx DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: how to use atof?
In-Reply-To: <7qufgt$3hm$1@thetenth.astat.de>
Message-ID: <Pine.SUN.3.91.990906094255.4874L-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sun, 5 Sep 1999, Berti Drost wrote:

> If I add
> #include <stdlib.h>
> it works correctly, if I don't, it can be compiled, but atof returns strange
> numbers; I wonder why...

Because C assumes that any function without a prototype returns an
int.  <stdlib.h> includes a prototype of `atof' that says it returns a
double, but if you omit it, the compiler generates code that
interprets the value returned by `atof' as an int, which indeed will
produce very strange results.

You should *always* include the headers with the prototypes of all the
library functions your program uses.  That is why the documentation
for every function in the DJGPP library reference always shows you
what header has the prototype.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019