greg@turbo.atl.ga.us (Greg Montgomery) (04/09/91)
I'm having a little problem with BC++ and functions that I didn't use the include files. For instance, I noticed using the fabs() function would actually increase the variable I was getting the abs of by 90 until I added a #include <math.h> in the top of the .C file. Why would this happen? I can't figure out why having a declaration (I think that's the right word??) would affect how the function actually works. I've noticed this a couple times tonight. I think the same thing happened with atof(). Any ideas on this?? Is this a normal C happening or a bug that needs to be reported to Borland? ---- Greg Montgomery | Montgomery Consultants, Inc. | Atlanta, Georgia, U.S.A Internet: greg@turbo.atl.ga.us | Home of the '96 UUCP: {rutgers,ogcise,gatech}!emory!turbo!greg | Olympics!
cadsi@ccad.uiowa.edu (CADSI) (04/10/91)
From article <Ze54Z1w164w@turbo.atl.ga.us>, by greg@turbo.atl.ga.us (Greg Montgomery): > I'm having a little problem with BC++ and functions that I didn't use > the include files. For instance, I noticed using the fabs() function > would actually increase the variable I was getting the abs of by 90 > until I added a #include <math.h> in the top of the .C file. > Why would this happen? I can't figure out why having a declaration (I > think that's the right word??) would affect how the function actually > works. I've noticed this a couple times tonight. I think the same thing > happened with atof(). Any ideas on this?? Is this a normal C happening > or a bug that needs to be reported to Borland? This is a standard C beginners problem. C assumes integer if not told otherwise. Thus, without the prototype in the math.h header file, atof is assumed to pass back an integer, not a double. In addition, without the prototype, the compiler will allow you to pass an integer to the function. Even uglier, since atof will read a double off the stack starting from where the integer was placed. |----------------------------------------------------------------------------| |Tom Hite | The views expressed by me | |Manager, Product development | are mine, not necessarily | |CADSI (Computer Aided Design Software Inc. | the views of CADSI. | |----------------------------------------------------------------------------|