From: dlc@cs.cmu.edu (Daryl Clevenger)
Subject: Re: Bug in OSF1.32 C compiler on alpha
Date: 1996/07/01 [thread overview]
Message-ID: <4r9lev$7pc@cantaloupe.srv.cs.cmu.edu> (raw)
In-Reply-To: 4r965l$inj@news.psc.edu
In article <4r965l$inj@news.psc.edu>, Nigel Goddard <ngoddard@psc.edu> 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 <stdio.h>
>
>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
next prev parent reply other threads:[~1996-07-01 4:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-07-01 4:00 Bug in OSF1.32 C compiler on alpha Nigel Goddard
1996-07-01 4:00 ` Daryl Clevenger [this message]
1996-07-01 4:00 ` Steve Peltz
1996-07-02 4:00 ` Dan Pop
1996-07-08 4:00 ` Steve Peltz
1996-07-08 4:00 ` Dan Pop
1996-07-02 4:00 ` Dan Pop
1996-07-03 4:00 ` Andy V
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox