[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Comparing pointers via cast to int?
From:       Thiago Macieira <thiago.macieira () kdemail ! net>
Date:       2004-10-28 20:31:19
Message-ID: 200410281731.19377.thiago.macieira () kdemail ! net
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Adriaan de Groot wrote:
>Now, senderFrame and viewFrame are both QObject *, and what's worse is
> that an int isn't necessarily big enough to hold those pointers. 

Agreed. That's a bug on 64-bit platforms.

> Would either of
>
>      if ( senderFrame && viewFrame && viewFrame != senderFrame )
>
>      if ( senderFrame && viewFrame &&
>           (void *)viewFrame != (void *)senderFrame )

The first one is better.

If that generates a warning, cast one of the pointers to the other one's 
type, using static_cast.

Also note that two pointers of different types may differ and yet point to 
the same object! The original comparison is more than flawed.

-- 
  Thiago Macieira  -  Registered Linux user #65028
   thiago (AT) macieira (DOT) info
    ICQ UIN: 1967141   PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

[Attachment #5 (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic