Re: [GD-General] meaning of sizeof(int) on all plateform
Brought to you by:
vexxed72
|
From: brian s. <pud...@po...> - 2003-06-28 21:13:49
|
It is wrong to assume that all pointers are the same size, even on
"normal" architectures. Pointers to class members are not required to
be sizeof(void *), and in the case of virtual inheritance, probably
aren't.
This program:
// Compile under VC++ with "cl /ML /GX test.cpp"
#include <iostream>
using namespace std;
struct Base
{
};
struct Derived : public virtual Base
{
};
typedef void (Base::*BasePtrToMember)();
typedef void (Derived::*DerivedPtrToMember)();
int main(int argc, char **argv)
{
cout << "sizeof(BasePtrToMember) " << sizeof(BasePtrToMember) << endl;
cout << "sizeof(DerivedPtrToMember) " << sizeof(DerivedPtrToMember)
<< endl;
return 1;
}
Produces the following output:
sizeof(BasePtrToMember) 4
sizeof(DerivedPtrToMember) 12
There you go, a 12 byte pointer on Win32. You can imagine that this
causes brain-bending bugs for the unwary :)
--brian
Jay Woodward wrote:
>Hold on -- it seems to me that the existence of forward declaration necessitates that all pointers be the same size.
>
>I suppose you wouldn't lose information when casting, as long as it's guaranteed that sizeof(void*) >= sizeof(any other pointer). Still, my understanding has always been that all pointers are the same size.
>
>
>
>
>>-----Original Message-----
>>From: Gareth Lewin [mailto:GL...@cl...]
>>Sent: Friday, June 27, 2003 1:45 AM
>>To: gam...@li...
>>Subject: RE: [GD-General] meaning of sizeof(int) on all plateform
>>
>>
>>btw, sizeof(pointer) isn't a real value, it is perfectly
>>valid for a certain
>>platform to have differant sizes of pointers, so sizeof (void*) is not
>>always == sizeof(int*).
>>
>>
|