4 ms·
C++ member pointers are frequently represented as offsets into the class on vanilla x86. Given that 0 is an entirely valid offset -- the first member given a c
by MaulingMonkey 13y ago
C++ member pointers are frequently represented as offsets into the class on vanilla x86. Given that 0 is an entirely valid offset -- the first member given a class without initial padding or vtable -- NULL must of course be represented by an entirely different, nonzero, bitpattern.
- icedchai 13y agohmm? you're adding an offset to a pointer (the base of the object), which is still not going to equal 0 even if the offset is 0.
- MaulingMonkey 13y agoThe C++ standard calls pointers to members... well, pointers to members. I'm not offsetting anything: The compiler is on my behalf. It could create function stubs for all I care, similar to how one might emulate this feature in C#. #include <iostream> struct Foo { int bar; }; int main() { int (Foo::*null_pointer) = nullptr; int (Foo::*first_member_pointer) = &Foo::bar; std::cout << *(std::ptrdiff_t*)&null_pointer << "\n"; std::cout << *(std::ptrdiff_t*)&first_member_pointer << "\n"; } Running this code after compiling it with VS2012 results in, on my machine: -1 0
- deleted 13y ago[deleted]