asjoshi@phoenix.Princeton.EDU (Amit S. Joshi) (12/12/87)
Hello, I came accross what could be a bug or I am missing somthing very obvious but I know not. Here is a short bit of Turbo C code which seems to give VERY absurd results. /**** code begins here ***/ #include <sdtio.h> #define reals float main() { reals c; c = -3.0; print_f(c); } print_f(c) reals c;{ printf("%f\n",c); } /***** code ends here ***/ Output should be "-3.0" ? Well guess again I get "0.00". If I change the line "#define reals float" to "define reals double" the code works fine. What the hell is happening ???? I used a large memory model, tcc, and tlink. I used mathl.lib and fp87.lib libraries beside the standard c0l.obj and cl.lib files. Any clues ??? Any fixes. Obviously this is not the code I was working on but is the distilled trouble section (got at after a lot of time and trouble).
drh@duke.cs.duke.edu (D. Richard Hipp) (12/13/87)
>I came accross what could be a bug or I am missing somthing very obvious >but I know not. Here is a short bit of Turbo C code which seems to give >VERY absurd results. See the correction below: /**** code begins here ***/ #include <sdtio.h> #define reals float int print_f(float c); /* This line inserted. */ main() { reals c; c = -3.0; print_f(c); } print_f(c) reals c;{ printf("%f\n",c); } /***** code ends here ***/ Turboc was promoting the "c" in the function call in "main" to a double, then "print_f" interpreted the double as a float which caused your problem. Defining the function "print_f" before you use it should clear things up. -R.
wtm@neoucom.UUCP (Bill Mayhew) (12/14/87)
Floating point arguments passed in TC are expected to be of type double. This isn't exactly a bug, as I've been told by people that are versed in K&R. I first ran into this when I used scanf. Quirks like this are what make programming so much fun. --Bill
psc@lznv.ATT.COM (Paul S. R. Chisholm) (01/01/88)
In article <1304@phoenix.Princeton.EDU>, asjoshi@phoenix.Princeton.EDU (Amit S. Joshi) writes: > #include <sdtio.h> > #define reals float > main() { > reals c; > > c = -3.0; > print_f(c); > } > print_f(c) > reals c;{ > printf("%f\n",c); > } Okay, one last time. There was a problem with functions that took float (not double) arguments in early versions of TC 1.0. The actual argument (in the call) was cast to double, as per K&R, but the formal argument (in the function definition) wasn't. (Or maybe the other way around. Doesn't matter.) No problem if you used doubles, or ANSI/C++ style function prototypes or definitions: print_f( float c) If you have an older copy of 1.0, you can get a patch from Borland. (The patch was on the net, too.) However, this bug is just plain fixed in my real, live, non-beta copy of TC 1.5, which is pretty nice anyway. 1.5 has just about everything 1.0 users asked for (except a debugger:-), and then some. I'll post comments on 1.5 when I have a chance. (Don't hold your breath.) -Paul S. R. Chisholm, {ihnp4,cbosgd,allegra,rutgers}!mtune!lznv!psc AT&T Mail !psrchisholm, Internet psc@lznv.att.com I'm not speaking for my employer, I'm just speaking my mind.