Search code examples
c++visual-studio-200564-bit

Member Variable Pointers in 64 bit environment


I've discovered while trying to use a luaBind-style class binding system that passing pointers to member variables doesn't seem to work right when compiling as a 64 bit app. Specifically:

class Foo {
    int a;
    int b;
};

With the above class getting &Foo::b in 32 bit will return (as expected) 0x00000004. The same call in 64 bit returns 0xCCCCCCCC00000004, which is 32 bits of correct and 32 bits of WTF.

My first thought is that this is a bug in the compiler (I'm using Visual Studio 2005 SP1 on Vista 64 Business), but that seems like a pretty big bug for a IDE that proudly claims 64 bit compatibility. Googling turns up nothing (but I may be using the wrong term. Member Variable Pointer? Anyone care to correct me?), so I'm curious if this is just me or a more widespread issue.


Solution

  • Try printing sizeof(&Foo::b).

    IIRC, in 64-bit VS2005 a pointer to member could occupy 4 or 12 bytes (depending on virtual/multiple inheritance), but IDE always displays 8 bytes (which (IMHO) is a bug in IDE ).