From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: X-Archive-Original-Message-ID: <9710062213.AA13215@shaman.zk3.dec.com> Date: Tue, 7 Oct 1997 02:08:50 +0200 (CEST) From: Volker Barthelmann Subject: Re: axp/gcc the double cast gets trashed on return 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