On Tue, 08 Dec 2009 18:13:48 +0000, Roland Scheidegger <srol...@vmware.com> wrote: > In particular, gcc man page warns that > union a_union { > int i; > double d; > }; > > int f() { > double d = 3.0; > return ((union a_union *) &d)->i; > } > > "might" not be ok (why not?), even though it doesn't seem to generate > any warnings. Hence don't use this and do the extra step to actually use > assignment to get the values in/out of the union. > This changes parts of 3456f9149b3009fcfce80054759d05883d3c4ee5.
I believe the issue here is not aliasing, but alignment. Some architectures require various different data types to be aligned differently, and so the result of casting from one to another is, according to ISO C, undefined. In practice, I believe it will cause GCC to emit slow unaligned data access code, which will typically use the data with multiple byte sized accesses. Hopefully, in practice, with strong (strict) restrictions on data, GCC will be able to eliminate the actual assignment steps when using a union. Matthew W.S. Bell
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________ Mesa3d-dev mailing list Mesa3d-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mesa3d-dev