From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,f4c619a88791a415 X-Google-Attributes: gid1164f8,public X-Google-Thread: 1450f6,f4c619a88791a415 X-Google-Attributes: gid1450f6,public From: dlc@cs.cmu.edu (Daryl Clevenger) Subject: Re: Bug in OSF1.32 C compiler on alpha Date: 1996/07/01 Message-ID: <4r9lev$7pc@cantaloupe.srv.cs.cmu.edu>#1/1 X-Deja-AN: 163181338 references: <4r965l$inj@news.psc.edu> organization: School of Computer Science, Carnegie Mellon newsgroups: comp.sys.dec,cmu.comp.sys.dec.alpha In article <4r965l$inj@news.psc.edu>, Nigel Goddard wrote: >Is this one known? Is there a fix? > >Briefly, code taking the address of a function parameter declared float >in the old style is not compiled correctly. I am not so sure that this is actually a bug. I don't have a copy of the old K&R, but the second addition of K&R, section A7.3.2, Function Calls has this to say (p 202, the 3rd full paragraph in my copy of the text) "If the function declaration in scope for a call is old-style, then default argument promotion is applied to each argument as follows: integral promotion (sec A6.1) is performed on each argument of integral type, and each float argument is converted to double. The effect of the call is undefined if the number of arguments disagrees with the number of parameters in the definition of the function, or if the type of an argument after promotion disagrees with that of the corresponding parameter. Type agreement depends on whether the function's definition is new-style or old-style. If it is old-style, then the comparison is between the the promoted type of the argument of the call and the promoted type of the parameter; ..." The way I see it, the progam does the right thing until G is called. Since F promotes x to double, you are really calling G(&x) with a double *, which is not the same as a float *. So in G(), *px only retrieves the first 4 bytes at px and then promotes this to a double. The are no automatic promotion rules for pointers, so the behavior may be correct since the type of the argument (double *) disagrees with the type of the parameter (float *). > >Here is a sample program > >#include > >static void G(px) > float *px; >{ > (void) printf("%f\n", *px); >} > >static void F(x) > float x; >{ > (void) printf("%f\n", x); > G(&x); >} > >int main () >{ > F(0.2); > return(0); >} > >Here is its output: > >axpfeb{66} cc -std0 bug.c -o bug >axpfeb{67} bug >0.200000 >-0.000000 >axpfeb{68} > >Nigel Goddard > -- Daryl Clevenger Member Technical Staff Transarc Corporation dlc@cs.cmu.edu