Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!cs.uoregon.edu!ogicse!hsdndev!dartvax!mars!nic!bbn.com!cjross From: cjross@bbn.com (chris ross) Newsgroups: comp.lang.c Subject: passing address of floating-point parameter Message-ID: <64623@bbn.BBN.COM> Date: 12 Jun 91 02:00:42 GMT Sender: news@bbn.com Reply-To: cjross@BBN.COM (chris ross) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 44 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 ---------- ---------- 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.