[comp.lang.c] Pointers to float parameters

dfp@cbnewsl.ATT.COM (david.f.prosser) (08/18/89)

In article <960@prlhp1.prl.philips.co.uk> yuleat@prlhp1.UUCP () writes:
>fn1(x)
>float x;
> {
>    float y= x;
>
>    fn2(&x, &y);
> }
>
>fn2(x, y)
>float *x, *y;
> {
>    printf("In fn2 values are x= %f & y= %f\n", *x, *y);
> }
>
>What I would like to know is whether this is what the compiler
>should do (I've looked in K&R and I couldn't find anything
>that addressed this problem specifically).

In section A.10.1 (page 205) of K&R (I), it states that float parameters
are "adjusted to read double".  This means that ``&x'' is actually a
pointer to double.  This all works out because (before prototypes) all
float argument expressions were widened to double as part of the function
call.

This has been changed with ANSI C.  Float argument expressions are still
widened to double for calls to old-style functions, but a float parameter
declaration in an old-style function definition is no longer "adjusted".
Instead, the behavior is as if the double value that was actually passed
is converted (usually in place) to float before the function proper begins.
(Much the same way that many architectures copy a value off the stack and
into a register for register parameters.)  Thus the above example will
output the same value for *x and *y for an ANSI C conforming compiler.

Dave Prosser	...not an official X3J11 answer...