Subject: RE: Amendment to post: atof() bug in b17.1 & b18?
From: [email-masked] (Colin Peters)

14 Jun 1997 22:47:40 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <01BC798B.63729540.cygnus.gnu-win32@gbird0>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Original-To: "[email-masked]'" <[email-masked]>
Original-Cc: "'GNU-Win32'" <[email-masked]>
Original-Sender: [email-masked]

E. Dennis[SMTP:[email-masked]] wrote:
>Hi.  Yes, more info.  Sorry.

Sorry if I sounded abrupt in that last post. However, the results
below just go to show that example code is important.

The code you give compiles and gives correct output on my system
(win95 P100) with either the Cygwin32 or Mingw32 libraries given
that you make one small change. The first line of your code should
read:

#include <stdlib.h>

If you don't do this atof is assumed to return an int, which gets
"converted" to a float, resulting in completely silly numbers. If
I leave out the include I get the same results as you under Cygwin32
and all numbers give the same large (and completely wrong) value
under Mingw32. (Why the results are different from the different
libraries is somewhat baffling I'll admit.)

If you compile with the -Wall option (all warnings on) you get this:

junk.c:3: warning: return-type defaults to `int'
junk.c: In function `main':
junk.c:11: warning: implicit declaration of function `atof'
junk.c:17: warning: implicit declaration of function `printf'

Line 3 is complaining about no return type for main. Line 11 is
the important one, because the implicit declaration assumes an
int to be returned.

After adding an int return type to main and including stdlib.h
and stdio.h all of these warnings go away and the code works
fine.

The moral of the story is to always try compiling with warnings
on. The second moral is to always prototype, especially if you
use functions that don't return int. :)

Hope this helps,
Colin.

-- Colin Peters - [email-masked]
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".