[Bug c++/15471] Incorrect member pointer offsets in anonymous structs/unions

bangerth at dealii dot org gcc-bugzilla@gcc.gnu.org
Wed May 26 11:40:00 GMT 2004


------- Additional Comments From bangerth at dealii dot org  2004-05-25 14:20 -------
I don't know what we're supposed to do here, but this is indeed 
surprising: 
----------------------- 
#include <stdio.h> 
 
struct myclass { 
    unsigned a; 
    union { 
        unsigned x; 
    }; 
}; 
 
int main () { 
  myclass foo; 
  unsigned myclass::* member = &myclass::x; 
  printf ("x -> %p %p\n", &(foo.*member), &foo.x); 
} 
----------------------- 
One would expect the two pointers to be the same, but they're not: 
 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc ; ./a.out  
x -> 0xbfffeaa0 0xbfffeaa4 
 
It has indeed to do with the anonymous union (which in this case only 
contains a single element), since if I remove it and bring the variable 
x to the myclass scope, then the problem disappears. 
 
W. 

-- 


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



More information about the Gcc-bugs mailing list