Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!wuarchive!uunet!sdrc!thor!scjones From: scjones@thor.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: Nasty bug Message-ID: <147@thor.UUCP> Date: 31 Aug 90 13:24:37 GMT References: <0093BF08.7F3834E0@rigel.efd.lth.se> Organization: SDRC, Cincinnati Lines: 33 In article <0093BF08.7F3834E0@rigel.efd.lth.se>, e89hse@rigel.efd.lth.se writes: > > 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. It is worth noting that different C compilers handle this situation differently. Some do exactly what you said, they rewrite your parameter declaration as double rather than float. Others assign the passed double value to a local float which is then used as the parameter. If the float and double formats are sufficiently similar, the compiler can just ignore the second half of the passed double value and leave the parameter a float without having to make a copy. ANSI C does not allow the declaration rewriting -- it requires the compiler to make the parameter have the type you declared it as. So, this problem should not be a problem much longer, right? ---- Larry Jones UUCP: uunet!sdrc!thor!scjones SDRC scjones@thor.UUCP 2000 Eastman Dr. BIX: ltl Milford, OH 45150-2789 AT&T: (513) 576-2070 Hello, I'm wondering if you sell kegs of dynamite. -- Calvin