From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jamie Lokier To: Rask Ingemann Lambertsen Cc: GCC mailing list Subject: Re: type based aliasing again Date: Tue, 21 Sep 1999 02:02:00 -0000 Message-id: <19990921110044.C26470@pcep-jamie.cern.ch> References: <1252.932T1013T12954349@kampsax.k-net.dk> X-SW-Source: 1999-09/msg00887.html Rask Ingemann Lambertsen wrote: > The recommendation in the GCC manual, if that is anything to go by, is > not to "cast to union" but to use a union. I.e. something like > > union foo { double a; int b[2]; }; > foo.a = 2.0; > foo.b[1] = 0; > > This is documented to work, actually works, is shorter, is not > write-only, etc. The problem is that you have to change all the code which uses a `foo', when you decide you want a particular piece of code to access it as an `int'. That means changing all the type declarations (previously might have been `double'), and every place where the type is accessed. That is often unworkable. With some variation on anonymous unions, it might be workable. Is that worth pursuing? -- Jamie From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jamie Lokier To: Rask Ingemann Lambertsen Cc: GCC mailing list Subject: Re: type based aliasing again Date: Thu, 30 Sep 1999 18:02:00 -0000 Message-ID: <19990921110044.C26470@pcep-jamie.cern.ch> References: <1252.932T1013T12954349@kampsax.k-net.dk> X-SW-Source: 1999-09n/msg00887.html Message-ID: <19990930180200.55QMuob2j2Pwm4Er6CBcxb1CcLB1HlgtZhB4miZ26kw@z> Rask Ingemann Lambertsen wrote: > The recommendation in the GCC manual, if that is anything to go by, is > not to "cast to union" but to use a union. I.e. something like > > union foo { double a; int b[2]; }; > foo.a = 2.0; > foo.b[1] = 0; > > This is documented to work, actually works, is shorter, is not > write-only, etc. The problem is that you have to change all the code which uses a `foo', when you decide you want a particular piece of code to access it as an `int'. That means changing all the type declarations (previously might have been `double'), and every place where the type is accessed. That is often unworkable. With some variation on anonymous unions, it might be workable. Is that worth pursuing? -- Jamie