Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!ucbvax!bloom-beacon!eru!hagbard!sunic!lth.se!E89HSE@rigel.efd.lth.se From: e89hse@rigel.efd.lth.se Newsgroups: comp.lang.c Subject: Nasty bug Message-ID: <0093BF08.7F3834E0@rigel.efd.lth.se> Date: 30 Aug 90 02:41:19 GMT Sender: newsuser@lth.se (LTH network news server) Reply-To: e89hse@rigel.efd.lth.se Organization: Lund Institute of Technology,Lund, Sweden Lines: 42 Hi ! I had a lot of trouble with a bug yesterday. The code was similar to the following: void main() { prnval("10.0",0.0); exit(0); } prnval(s,f) char *s; float f; { if(f == 0.0) sscanf(s,"%f",&f); printf("%10.2f\n",f); } And it didn't work. Why? The answer is that the parameter f is a double, not a float since all floats are converted to double when they are passed as arguments to functions. Therefore &f is a ptr to double rather than a ptr to float as one would expect looking at the declartion. Later I rewrote prnval() as: prnval(s,f) char *s; double f; { if(f == 0.0) sscanf(s,"%lf",&f); printf("%10.2f\n",f); } Well, I hope I'll help someone to avoid that problem... It took me a while to figure out why the code didn't work... Henrik Sandell Disclaimer: I know that this code wouldn't pass lint without warnings, but that is not the purpose of the code...