Nasty bug
Kjartan Pierre Emilsson
pierre at rhi.hi.is
Thu Aug 30 18:52:35 AEST 1990
>From article <0093BF08.7F3834E0 at rigel.efd.lth.se>, by e89hse at rigel.efd.lth.se:
> Hi !
>
> I had a lot of trouble with a bug yesterday. The code was similar to the
> following:
>
> [Code deleted]
> prnval(s,f)
> char *s;
> float 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 float.
>
> Henrik Sandell
I don't know what other think, but as a relatively experienced C programmer, I
find this bug very counter-intuitive, being used to think that when I declare
some variable in code to be of a given type, I certainly want it to be
of that given type, regardless of what crap I choose to put in it later.
>From that point of view, float variables should not be allowed in function
argument declaration. Personally I never use floats, but this is certainly
a *very* nasty bug.
-Kjartan
-------------------------------------------------------------------------
Kjartan Pierre Emilsson
Science Institute of the University of Iceland
Dunhaga 3
Reykjavik
ICELAND e-mail: pierre at krafla.rhi.hi.is
More information about the Comp.lang.c
mailing list