🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #42654

Programmer error (was Re: scanf problem in TC v2.01.)

#42654
From: John F. Bruno
Date: Mon, 19 Feb 1990 16:14
40 lines
1877 bytes
In article <204@sdscal.UUCP> keith@sdscal.UUCP (Keith Jones) writes:
 [ message asking for bug details omitted ]
 >
 >Well, I didn't quite believe it, but I made this test file and sure enough,
 >the printf doesn't print out anything that even looks like it approximates
 >PI.
 >
 >----- to cut ----- or not to cut -----
 >main()
 >{
 >    float f;
 >    char *string = "3.1415926";
 >
 >    f = atof( string );
 >    printf( "pi = %f\n", f );
 >}
 >----- be it here ----- or there -----
 >
 >The output to this program was:
 >
 >D:\ -> test
 >
 >-8209.00000
 >
 >and I compiled it with:
 >
 >D:\ -> tcc test
 >
 >I'm not particularly worried about this bug, but I figured I might as well
 >post the program.
 
atof() takes a character pointer as its argument and returns a float, in C,
anytime you don't explicitly declare what a function returns, it is assumed
to be an integer (I know, I would prefer a warning also), that's what 
happened in this case, because you didn't #include <math.h> I got the same
result with my test program, but when you include the prototype for atof(),
it works perfectly. If you look up atof() in the Turbo-C reference guide, it
says "prototype in math.h,stdlib.h"

---jb
Technical Details
Message-ID: <2126@rodan.acs.syr.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!rpi!uupsi!rodan!jfbruno
References: <7192.25d1e107@dit.ie> <25D4D935.3073@maccs.dcss.mcmaster.ca> <25D8649A.24584@maccs.dcss.mcmaster.ca> <204@sdscal.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!rpi!uupsi!rodan!jfbruno
From: jfbruno@rodan.acs.syr.edu (John F. Bruno)
Newsgroups: comp.sys.ibm.pc
Subject: Programmer error (was Re: scanf problem in TC v2.01.)
Summary: Ain't no bug here, only programmer error
Message-ID: <2126@rodan.acs.syr.edu>
Date: 19 Feb 90 16:14:55 GMT
References: <7192.25d1e107@dit.ie> <25D4D935.3073@maccs.dcss.mcmaster.ca> <25D8649A.24584@maccs.dcss.mcmaster.ca> <204@sdscal.UUCP>
Reply-To: jfbruno@rodan.acs.syr.edu (John F. Bruno)
Organization: Syracuse University, Syracuse, NY
Lines: 40