This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: B19: gcc/libc bug with call to atof() (Win95)


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".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]