| > - what is the meaning/purpose of the double type-casting
> used twice in the documentation (section 5.10.18.1, for example)
> like this:
>
> MYCLASS () : MYSERVER((void *)(MYSERVER *) this) {};
Keep in mind that in C++, when one class is derived from another,
the pointers value may change when cast (either explicitly or
implicitly) between the two classes. The compiler knows how much
to adjust the pointer by. However once you've cast a pointer to
the void pointer, the compiler can no longer do this, it's up to
the programmer to make sure that when they cast the void pointer
back into a pointer to a class, that they cast it back to a pointer
to the same exact class that it really is a pointer to.
For example (and I believe a similiar example is in the ARM):
class A {int x;};
class B : A {int y;};
B b;
void *pv = (void *)&b;
A *pA = (A *)pv;
the above code is not portable. pA may or may not be set correctly
depending on the implementation of the compiler. For the above
to be portable you need a double cast such as:
A *pA = (A *)(B *)pv;
|