Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpda!hpcuhb!hpcllla!hpcllca!walter From: walter@hpcllca.HP.COM (Walter Murray) Newsgroups: comp.lang.c Subject: Re: Nasty bug Message-ID: <7330028@hpcllca.HP.COM> Date: 30 Aug 90 16:14:33 GMT References: <0093BF08.7F3834E0@rigel.efd.lth.se> Organization: Hewlett Packard Calif. Language Lab Lines: 29 Henrik Sandell writes: > I had a lot of trouble with a bug yesterday. The code was similar to the > following: [Program using an old-style (non-prototype) function definition with a parameter of type float] >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. > 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... You got bit by what is called type rewriting, something that was done by some pre-ANSI compilers. Although you declared the parameter as float, the compiler acted exactly as if you had declared it as double. Some compilers may also do this with parameters of type char or short, pretending that you had actually declared them as int. Type rewriting is not permitted for a compiler that conforms to the ANSI standard. A program that relies on type rewriting may not behave as expected when compiled with a standard-conforming compiler. For more information, see section 3.7.1 of the ANSI C Rationale. Walter Murray ------