T
Tim Rentsch
James Kuyper said:On 12/18/2013 03:44 AM, JohnF wrote:
...
C has anti-aliasing rules, that allow a compiler to optimize code by
assuming that a pointer to long, for instance, will never point at
the same location as a pointer to double.
Within the scope of the declaration of such a union, code which
might refer to members of such a union object is allowed, that
would otherwise violate the anti-aliasing rules.
The last sentence isn't right. Implementations are always free
to assume that a (long *) and a (double *) don't alias the same
memory, even if there is a union definition in scope that has a
'long' member and a 'double' member. The only exception to this
principle is the "one special guarantee" given in 6.5.2.3. If
one of the accesses goes through a union type explicitly, eg,
'u->double_member', that's a different story; but if what we
have is just direct pointers (so no member access operators
needed), whether some union is defined or not does not affect
which kinds of aliasing must be accommodated.