This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: type based aliasing again
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