Float Double Parameters

Henry Spencer henry at utzoo.UUCP
Sun Mar 30 15:06:28 AEST 1986


> >	Taking the address of "float" formal function parameters does not
> >	work right.
> >	...
> >     ... The
> >problem seems to be related to the way the C compiler promotes floats to
> >doubles in function  calls.    That  is, foo() knows that its caller  is
> >really going to pass a double rather than a float, so it behaves as if r
> >were a double.  The trouble is, when we take the address of r, which  is
> >supposedly a float variable, the pointer  actually points  to a  double!
> >This  is hardly the behaviour I expect from applying the "&" operator to
> >a variable which has been declared "float".
> 
> X3J11 says "arguments that have type float are promoted to double". Too bad.
> 
> The bug is real, but you've only been bitten by it because you are following
> bad programming practice in trying to make a parameter do two jobs...

der Mouse is actually dead wrong here; in pre-X3J11 C there is NO SUCH
THING as a "float" formal parameter.  If you read the C Reference Manual
section 10.1, you will find that when declaring formal parameters, "float"
is a synonym for "double".  Whether this is bad design is a valid question,
but saying that such a formal parameter is "supposedly a float variable"
is simply the result of misunderstanding an (admittedly subtle) detail
of the language.  It is not a float variable, it is a double variable
declared in a strange and misleading way.  Not a compiler bug.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.lang.c mailing list