Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: vesper@vesper.enet.dec.com (Andy V)
Subject: Re: Bug in OSF1.32 C compiler on alpha
Date: 1996/07/03	[thread overview]
Message-ID: <4rds4d$5a8@peavax.eng.pko.dec.com> (raw)
In-Reply-To: 4r965l$inj@news.psc.edu



Nigel Goddard <ngoddard@psc.edu> 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



      parent reply	other threads:[~1996-07-03  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 ` 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-01  4:00 ` Daryl Clevenger
1996-07-02  4:00 ` Dan Pop
1996-07-03  4:00 ` Andy V [this message]
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