------- Comment #8 from rguenth at gcc dot gnu dot org  2007-07-24 12:09 -------
You may only access union members through the union, not through other
pointers.
GCC is perfectly valid in caching n->next in the first example.  So, for
comment #4, it is true that &u.a.n.next == &u.b.n.prev, but you have to do
accesses to n->next and n->prev through the _union_, otherwise the example
is not valid.  So you you would need

  struct node {
    union u *prev;
    union u *next;
  };

  union {
    struct {
      void* unused;
      struct node n;
    } a;
    struct node b;
  } u;

or another creative way of doing all accesses to ->prev and ->next through
the union type.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32856

Reply via email to