Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.lang.c Subject: Re: Float Double Parameters Message-ID: <6549@utzoo.UUCP> Date: Sun, 30-Mar-86 00:06:28 EST Article-I.D.: utzoo.6549 Posted: Sun Mar 30 00:06:28 1986 Date-Received: Sun, 30-Mar-86 00:06:28 EST References: <2600042@ccvaxa> Organization: U of Toronto Zoology Lines: 28 > > 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