Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Volker Barthelmann <volker@vb.franken.de>
Subject: Re: axp/gcc the double cast gets trashed on return
Date: Tue, 7 Oct 1997 02:08:50 +0200 (CEST)	[thread overview]
Message-ID: <d60ccffdb40893983d561111061dd5d6.axp-list@archive.invalid> (raw)
In-Reply-To: <3438FA7E.E8FD1D28@voicenet.com>

On Mon, 6 Oct 1997, Uncle George wrote:

> Hi,tell me why the double value returned from go_convert() is not 7.0???
> If u step through ( via gdb ) the val l.dd = 7, x.dd = 7,
> 
>     BUT d.dd is some bogus number. d.dd should have 7.0

I added a printf() and got 7.0 here. BUT...

> Am I doing something wrong ( u cannot change the code, unless there is a "C"
> violation somewhere!!!!)

The code is basically broken. Reading another member of a union than the
one which was last written causes implementation defined behaviour (IMHO
it should even be undefined behaviour).
And I don't know if gcc documents its behaviour here. You really shouldn't
do such things because there are compilers that will break such code.

The only clean way to do that is to use a bytewise copy, e.g. with
memcpy(). Things like *((double*)&l.ll) will also cause trouble.

Volker

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

  parent reply	other threads:[~1997-10-07  0:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3438FA7E.E8FD1D28@voicenet.com>
1997-10-06 17:03 ` axp/gcc the double cast gets trashed on return Richard Henderson
1997-10-07  0:08 ` Volker Barthelmann [this message]
1997-10-06 18:35 Uncle George
  -- strict thread matches above, loose matches on Subject: below --
1997-10-06 14:49 Uncle George
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