using floats in functional prototypes

Ralf.Brown at B.GP.CS.CMU.EDU Ralf.Brown at B.GP.CS.CMU.EDU
Thu Jan 19 22:33:05 AEST 1989


In article <1989Jan18.092522.14499 at gpu.utcs.toronto.edu>, romwa at gpu.utcs.toronto.edu (Royal Ontario Museum) writes:
}I am having some problems with using float's in functional
}prototypes ...
}When I compile the two files, I get a warning that the type of
}the argument in the prototype doesn't match the declaration
}---------tst2.c------------------------------------------------
}#include <stdio.h>
}
}void afunc( float );
}
}void afunc( flt_val )
}
}float flt_val;
}
}{
}  int i;
}
}  i = 3;
}}
}

The problem is that you are using an old-style declaration.  In old-style
declarations, parameters get widened according to specific rules.  One of
the rules is that floats get widened to double, so you are really declaring
a function that takes a double parameter.  That's why the compilers complain,
and also why you get garbage for the parameter--it is taking the four bytes
for the float plus an additional four bytes of garbage from the stack and
trying to interpret that as a double.

If you're going to use prototypes, you're pretty much going to have to use
new-style declarations when defining functions.
(i.e. void afunc(float flt_val) )

--
UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=-=-=- Voice: (412) 268-3053 (school)
ARPA: ralf at cs.cmu.edu  BIT: ralf%cs.cmu.edu at CMUCCVMA  FIDO: Ralf Brown 1:129/31
			Disclaimer? I claimed something?
	You cannot achieve the impossible without attempting the absurd.



More information about the Comp.lang.c mailing list