On Sun, 22 Jan 2006, Richard Guenther wrote: > ISO C says that the following violates aliasing rules: > > int foo(float f) > { > union { int i; float f; } u; > i.f = f; > return i.i; > } > > because the memory at u is accessed as two different effective types. > Using a union doesn't change this. The correct solution for converting > a float to an integer (bit-representation) as in the expample is to use > two different memory locations and memcpy (which avoids aliasing > issues by means of using the special rules for access through 'char').
It's not at all clear which types (of the union, or the union member) are the relevant effective types in such cases. Certainly N1111 treats such cases as intended to be defined, and the response to DR#283 makes the possibility of type punning through unions explicit (albeit in a footnote, i.e. non-normative). -- Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/ [EMAIL PROTECTED] (personal mail) [EMAIL PROTECTED] (CodeSourcery mail) [EMAIL PROTECTED] (Bugzilla assignments and CCs)