• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Any way to tell if a pointer is an object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any way to tell if a pointer is an object?


  • Subject: Re: Any way to tell if a pointer is an object?
  • From: "Clark Cox" <email@hidden>
  • Date: Sun, 25 Feb 2007 03:44:55 -0500

On 2/25/07, Jerry Krinock <email@hidden> wrote:
on 07/02/24 20:51, Ricky Sharp at email@hidden wrote:

> whereas 'theObjectPointer' did.  For example, you should see a
> familiar class name in the 'name' field:
>
> (id)0x43aa50       0x43aa50
>      isa            0x402910
>         isa         0xa295fed8
>         super_class 0xa295a3b8
>         name        0xa295a3b8  NSCFArray
>         ...

Thanks, Ricky.  Indeed, I can see this in gdb.

Ah, but I should not have used the word "debug".  I'm a lazy Cocoa
programmer; I don't do a debug build and fire up gdb unless I've got
something really gnarly going on.

I would recommend doing just the opposite; build debug first, and work primarily in a debug environment. Your debug build should be very pedantic about it's errors (i.e. crashing intentionally at the smallest fault). Only after the very strict debug build ceases to crash, do you start working on your release build (which should be more forgiving of errors, as users don't tend to enjoy hard crashes).

I should have asked this instead:

Is there any way to test whether or not a pointer points to an object before
sending it a message, to avoid the possible crash that will occur if it does
not point to an object?

Not really. Such guessing, outside of the debugger, is rarely a good idea. You should already know what any particular pointer points to (i.e. why would you be using or passing it in the first place if you didn't know what it was?).

In the context of a contextInfo param (no pun intended), there is
likely a small number of items that it could be pointing to. If there
is a possibility that it may point to something unexpected (i.e. some
other library/bundle/whatever is also calling your callback method)
then keep pointers around and do a simple equality comparison.


-- Clark S. Cox III email@hidden _______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Any way to tell if a pointer is an object? (From: Ricky Sharp <email@hidden>)
 >Re: Any way to tell if a pointer is an object? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Newbie: Dynamically filling NSTableView
  • Next by Date: Parsing STDout into an NSDictionary
  • Previous by thread: Re: Any way to tell if a pointer is an object?
  • Next by thread: Re: Any way to tell if a pointer is an object?
  • Index(es):
    • Date
    • Thread