This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
Re: B19: gcc/libc bug with call to atof() (Win95)
- To: Martin Hansen <m dot hansen at widex dot com>
- Subject: Re: B19: gcc/libc bug with call to atof() (Win95)
- From: Stephen Vance <vance at deneb dot com>
- Date: Wed, 28 Oct 1998 09:00:13 -0500
- CC: gnu-win32 at cygnus dot com
- Organization: Deneb Robotics, Inc.
- References: <3635B86F.93BBC51A@widex.com>
Martin Hansen wrote:
> which is wrong for the float value but right for the int value. (This
> is the bug, part2). First when you add the line '#include <stdlib.h>'
> to the program and recompile it, you get the desired behaviour.
This is your clue. This is not a bug. C does not have "built-in" functions
(excepting keywords with function syntax like sizeof), only functions defined by the
Standard Library. The function atof is prototyped in the header stdlib.h. Without
a prototype, floats are promoted to doubles. A good C book can explain the details
well.
What you are probably seeing is the float returned from atof() promoted to a double
and its first sizeof(float) bytes are being pulled off the stack by the stdarg
mechanisms used to implement printf(). The first four bytes of a double containing
the small value you are trying to print will be all 0s. Thus, it prints 0s.
--
Stephen Vance | http://www.deneb.com
Deneb Robotics, Inc. | mailto:vance@deneb.com
5500 New King Street | Phone: (248) 267-9696
Troy, MI 48098-2615 | Fax: (248) 267-8585
What is done well is done quickly enough. -Augustus Caesar
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".