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: Amendment to post: atof() bug in b17.1 & b18?


E. Dennis[SMTP:e.dennis@pemail.net] 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 - colin@bird.fu.is.saga-u.ac.jp
-- 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
"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]