[Patch] Fix undeleted "static QFont *_font" in kglobalsettings.cpp

Olivier Goffart ogoffart at kde.org
Sun Dec 14 22:41:21 GMT 2008


Le dimanche 14 décembre 2008, Thiago Macieira a écrit :
> Olivier Goffart wrote:
> >#include <iostream>
> >struct A {
> >        int a;
> >        int b;
> >};
> >int main() {
> >        int A::*m = 0;
> >        int A::*n = &A::a;
> >        std::cout << " m = " << *(int*)(&m) << ", n = " << *(int*)(&n)
> > << std::endl; }
> >
> >Compiles this program with gcc and the result is:
> > m = -1, n = 0
> >
> >Because the pointer is relative, the 0x000000 binary value points to the
> > first member in the class.  So the sementic value 0 or NULL need to be
> > something else (hence -1)
>
> Pointer to members usually cause this kind of problem.

This is not a problem.

This was just an illustration of what you were saying: 
The fact that the NULL or 0x0 could mean something else than all bit to zero.  
Using memset with zero to clear an array of pointer to member would be wrong 
even in a common platform. 

> You have to be very careful, since the sizeof may not be the size of a
> pointer. See: 
>
> $ cat > file.cpp
> class A { void f(); };
> int main() { typedef void (A::* pmf)(); return sizeof(pmf); }
>
> $ g++ -o file file.cpp
> $ ./file; echo $?
> 8
>
> This was on a 32-bit architecture.

You are using pointer to member _function_  which need to store the offset 
to 'this' in addition to the address of the function itself.
and a NULL here is still all bits to zero (on 8 bytes, but still zero)



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20081214/c9d38399/attachment.sig>


More information about the kde-core-devel mailing list