passing address of floating-point parameter

chris ross cjross at bbn.com
Wed Jun 12 12:00:42 AEST 1991


Here's something to feed to your compiler.

Define a routine which takes a (float) parameter and passes the address to a
routine which expects a (float*).  What value do you get when following the
pointer in the second routine?  Under Vax Ultrix and Masscomp RTU, I get
what I passed the first routine.  Under SunOS and MIPS RISC/OS, I get
something different.

Here's the code.  It should print
  1 1
  1 1


main ()
{
    foo(1.0, 1.0);
}

foo (x, y)
float x, y;
{
    float local_x = x;
    show(&local_x, &y);
    printf("%g %g\n", x, y);
}

show (xp, yp)
float *xp, *yp;
{
    printf("%g %g\n", *xp, *yp);
}


Apparently, the Sun and MIPS compilers do not hide the fact that the
parameter in the first routine is actually on the stack as a (double).
Should they, or, as with va_arg, must the programmer explicitly take the
type promotion into account?  Does ANSI specify the proper behavior?


----------  chris ross  ----------  <cjross at bbn.com>  ----------
lisp in action is like a finely choreographed ballet.
ada in action is like a waltz of drugged elephants.
c in action is like a sword dance on a freshly waxed floor.



More information about the Comp.lang.c mailing list