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: vesper@vesper.enet.dec.com (Andy V) Subject: Re: Bug in OSF1.32 C compiler on alpha Date: 1996/07/03 Message-ID: <4rds4d$5a8@peavax.eng.pko.dec.com>#1/1 X-Deja-AN: 163479153 distribution: world references: <4r965l$inj@news.psc.edu> organization: Digital Equipment Corporation reply-to: andy.vesper@eng.pko.dec.com newsgroups: comp.sys.dec,cmu.comp.sys.dec.alpha Nigel Goddard writes: >Briefly, code taking the address of a function parameter declared float >in the old style is not compiled correctly. Actually, the program itself is broken. You are passing the address of a double (float is re-written to double per old C rules) to a routine that expects the address of a float. This will `work' on a VAX or ALPHA using F- and D-float formats because the first half of a D-float format looks `just like' the near-equivalent F-float format. Moral -- move to function prototypes as quickly as possible. >static void G(px) > float *px; >{ > (void) printf("%f\n", *px); >} This says I have a routine G that assumes it will get a pointer to a float; but don't let the compiler notice when it is called with anything else. >static void F(x) > float x; >{ > (void) printf("%f\n", x); > G(&x); >} This says I have a routine F that assumes it will get a double (per old C argument re-writing rules) and passes its address to routine G. The compiler isn't allowed to know that G expects the address of a float, or it would complain. If you do: static void G (float *px) { (void) printf ("%f\n", *px);} static void F (float x) { (void) printf ("%f\n", x); G(&x); } it will work perfectly (barring typos), or if you do: static void G (float *px) { (void) printf ("%f\n", *px);} static void F (double x) { (void) printf ("%f\n", x); G(&x); } it will complain about the mis-matched arguments. -- Andy V (A Digital spoke, not a Digital Spokesperson) mailto:andy.vesper@eng.pko.dec.com