B19: gcc/libc bug with call to atof() (Win95)
Stephen Vance
vance@deneb.com
Wed Oct 28 06:00:00 GMT 1998
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".
More information about the Cygwin
mailing list